Results 1 to 9 of 9

Thread: Sending mail using Lotus Notes

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2000
    Location
    Sweden
    Posts
    155

    Sending mail using Lotus Notes

    Hi

    I can send mail using lotus notes and attach files to this mail.

    BUT, when I try to add multiple recipients the mail only goes to the first in the list

    I'm using the following code to do it


    Code:
    Public Function SendNotesMail(Recipient As String, Optional Subject As String = "", Optional BodyText As String = "", Optional Attachment As String = "", Optional SaveIt As Boolean = True) As Boolean
    
        Dim Maildb As Object 'The mail database
        Dim USERNAME As String 'The current users notes name
        Dim MailDbName As String 'THe current users notes mail database name
        Dim MailDoc As Object 'The mail document itself
        Dim AttachME As Object 'The attachment richtextfile object
        Dim Session As Object 'The notes session
        Dim EmbedObj As Object 'The embedded object (Attachment)
        
        On Error GoTo Notes_Err
        
        'Start a session to notes
        Set Session = CreateObject("Notes.NotesSession")
        'Get the sessions username and then calculate the mail file name
        'You may or may not need this as for MailDBname with some systems you
        'can pass an empty string
        USERNAME = Session.USERNAME
        MailDbName = Left$(USERNAME, 1) & Right$(USERNAME, (Len(USERNAME) - InStr(1, USERNAME, " "))) & ".nsf"
        'Open the mail database in notes
        Set Maildb = Session.GETDATABASE("", MailDbName)
         If Maildb.ISOPEN = True Then
              'Already open for mail
         Else
             Maildb.OPENMAIL
         End If
        'Set up the new mail document
        Set MailDoc = Maildb.CREATEDOCUMENT
        MailDoc.Form = "Memo"
        MailDoc.sendto = Recipient
        MailDoc.Subject = Subject
        MailDoc.Body = BodyText
        MailDoc.SAVEMESSAGEONSEND = SaveIt
        'Set up the embedded object and attachment and attach it
        If Attachment <> "" Then
            Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
            Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
            MailDoc.CREATERICHTEXTITEM ("Attachment")
        End If
        'Send the document
        MailDoc.send 0, Recipient
        SendNotesMail = True
        
    Notes_Resume:
        'Clean Up
        Set Maildb = Nothing
        Set MailDoc = Nothing
        Set AttachME = Nothing
        Set Session = Nothing
        Set EmbedObj = Nothing
        Exit Function
        
    Notes_Err:
        SendNotesMail = False
        GoTo Notes_Resume
    End Function
    any ideas??

    /C

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    Does this help?? I haven't used it, but found it on this forum once.

    Multiple Recipients:
    VB Code:
    1. strRecipient(1) = "[email protected]"
    2. strRecipient(2) = "[email protected]"
    3. Doc.Send(True, strRecipient)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2000
    Location
    Sweden
    Posts
    155
    thanks

    that helped

    I turned the 'recipient' string into an array

    it now works fine!!

    thanks again

    /C

  4. #4
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Here's what I have...It's crap code and I HATE, HATE, HATE, HATE Lotus notes
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const SERVER As String = "\\Fil-Notes01/Mail/"
    4.  
    5. Public Function SendMail(ByVal strRecipients As String, strSubject As String, ByVal strBody As String, ByVal blnSave As Boolean) As Boolean
    6. Dim objSession      As Object
    7. Dim objMailDB       As Object
    8. Dim objMailDoc      As Object
    9. Dim strUsername     As String
    10. Dim strMailDBName   As String
    11. On Error GoTo Errorhandler
    12.     Set objSession = CreateObject("Notes.NotesSession")
    13.     strUsername = objSession.Username
    14.     If strUsername <> vbNullString Then
    15.         strMailDBName = Right(strUsername, Len(strUsername) - InStr(strUsername, "="))
    16.         strMailDBName = Left(strMailDBName, InStr(strMailDBName, "/") - 1)
    17.         strMailDBName = Mid(strMailDBName, 1, 1) & Right(strMailDBName, Len(strMailDBName) - InStr(strMailDBName, " "))
    18.         strMailDBName = strMailDBName & ".nsf"
    19.     End If
    20.    
    21.     Set objMailDB = objSession.GETDATABASE(SERVER, strMailDBName)
    22.     If Not objMailDB.IsOpen Then
    23.         objMailDB.OPENMAIL
    24.     End If
    25.     Set objMailDoc = objMailDB.CREATEDOCUMENT
    26.     With objMailDoc
    27.         .Form = "Memo"
    28.         .PostedDate = Now()
    29.         .SaveOnMessageSend = blnSave
    30.         .SendTo = strRecipients
    31.         .Subject = strSubject
    32.         .Body = strBody
    33.         .SEND 0, strRecipients
    34.     End With
    35. Errorhandler:
    36.     Set objMailDoc = Nothing
    37.     Set objMailDB = Nothing
    38.     Set objSession = Nothing
    39.     If Err.Number <> 0 Then
    40.         If Err.Source = App.EXEName Then
    41.             Err.Raise Err.Number, "LTRServer - modLotusNotes - SendMail", Err.Description
    42.         Else
    43.             Err.Raise Err.Number, Err.Source, Err.Description
    44.         End If
    45.         SendMail = False
    46.     Else
    47.         SendMail = True
    48.     End If
    49. End Function
    50.  
    51. Public Function ValidEmail(ByVal EmailAddress As String) As Boolean
    52.     If Trim$(EmailAddress) <> vbNullString Then
    53.         ValidEmail = True
    54.     End If
    55. End Function
    Notice my great ValidateEmail function

    Sending the same email to many recipients is crap as it won't allow "[email protected], [email protected]"....it gives an error!
    STUPID LOTUS NOTES!!!



    Woka

  5. #5

  6. #6
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    Glad to be of help.

    I agree with your sentiments so eloquently expressed

  7. #7
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    Hahaha...I have never been one to mince around with soft-arse descriptions, I generally say it how it is.

    Our network guys think its the dogs-bollox God knows why!
    Oh, and they love Novell too

    One thing about using Notes is that it's almost impossible to get SQL Server to send emails via it Booooooooooooooo

    IBM Sucks

    Woka

  8. #8
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Washington DC
    Posts
    330

    Help Please

    That is great code for Lotus, but being I am completely stupid, how do you turn the string into an array for this to work?

    or have you found an easier way?

    Thanks,

    Susan
    Swoozie
    Somedays you just should not get out of bed.

  9. #9
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    OK use:
    VB Code:
    1. Private Function ConvertToArray(ByVal pstrRecipients As String) As String()
    2. Dim strArray() As String
    3.    strArray = Split(pstrRecipients, ",")
    4.    ConvertToArray = strArray
    5. End Function
    This works if you have seperated the email addresses with a comma, if you have used a semi colon then use:
    VB Code:
    1. Private Function ConvertToArray(ByVal pstrRecipients As String) As String()
    2. Dim strArray() As String
    3.    strArray = Split(pstrRecipients, ";")
    4.    ConvertToArray = strArray
    5. End Function
    The ";" in the Split function is the character that seperates the email addresses.
    Hope that works.
    Oh, the Split function is for VB6, not VB5.
    I am not using MS Ecxhange and am well happy
    Feel sorry for u using Lotus

    Woof

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width