+ Reply to Thread
Results 1 to 10 of 10

vba to send email and attachments via lotus 8.5

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-04-2010
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    143

    vba to send email and attachments via lotus 8.5

    Hi all,

    I have found a code at http://www.fabalou.com/VBandVBA/lotusnotesmail.asp. The code is supposed to send email and attachment using vba.
    'Public Sub SendNotesMail(Subject as string, attachment as string,
    'recipient as string, bodytext as string,saveit as Boolean)
    'This public sub will send a mail and attachment if neccessary to the
    'recipient including the body text.
    'Requires that notes client is installed on the system.
    Public Sub SendNotesMail(Subject As String, Attachment As String, Recipient As String, BodyText As String, SaveIt As Boolean)
    'Set up the objects required for Automation into lotus notes
        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)
        'Start a session to notes
        Set Session = CreateObject("Notes.NotesSession")
        'Next line only works with 5.x and above. Replace password with your password
        Session.Initialize("password")
        '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 or using above password you can use other mailboxes.
        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.PostedDate=Now() 'Gets the mail to appear in the sent items folder
        MailDoc.SEND 0, Recipient
        'Clean Up
        Set Maildb = Nothing
        Set MailDoc = Nothing
        Set AttachME = Nothing
        Set Session = Nothing
        Set EmbedObj = Nothing
    End Sub
    qn1 : which "UserName" should i change to my own username?
    eg, my username is Dan2010.
    UserName = Session.UserName
        MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
    do i change all the "UserName"?

    qn2 : which "Attachment" should i change to the location of my attachment?
    for eg, my attachment is at c:\Users\Dan\newfolder
     If Attachment <> "" Then
            Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
            Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment, "Attachment")
            MailDoc.CREATERICHTEXTITEM ("Attachment")
    qn3 : what other commands do i have to add if i need to attach more than 1 attachment?
    ps : my attachments can be in pdf format or jpeg

    Thanks alot in advance

    Regards,
    Dan
    Last edited by dan2010; 11-02-2010 at 09:02 PM.

  2. #2
    Forum Contributor
    Join Date
    08-04-2010
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    143

    Re: vba to send email and attachments via lotus 8.5

    anybody know how to answer my 3 questions?

  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: vba to send email and attachments via lotus 8.5

    I'm off out soon so haven't time to specifically answer your questions (I also don't use Lotus any more so can't test anything) but the attached is a more simplified code for sending a workbook as an attachment via Lotus. In this case it's the active workbook but can be quite easily adapted to be any file you want.

    To add more than one attachment you would just either repeat these lines with the specific attachment required assigned to stAttachment or create some kind of loop:

      Set noAttachment = noDocument.CreateRichTextItem("stAttachment")
    
      Set noEmbedObject = noAttachment.EmbedObject(EMBED_ATTACHMENT, "", stAttachment)

    Hope it helps,

    Dom
    Attached Files Attached Files
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  4. #4
    Forum Contributor
    Join Date
    08-04-2010
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    143

    Re: vba to send email and attachments via lotus 8.5

    Quote Originally Posted by Domski View Post

    To add more than one attachment you would just either repeat these lines with the specific attachment required assigned to stAttachment or create some kind of loop:

      Set noAttachment = noDocument.CreateRichTextItem("stAttachment")
    
      Set noEmbedObject = noAttachment.EmbedObject(EMBED_ATTACHMENT, "", stAttachment)
    do u mean this?
    eg.
    Set noAttachment = noDocument.CreateRichTextItem("c:\Users\Dan\newfolder\filename")
    and for multiple attachments,

    Set noAttachment = noDocument.CreateRichTextItem("c:\Users\Dan\newfolder\filename1")
    
      Set noEmbedObject = noAttachment.EmbedObject(EMBED_ATTACHMENT, "", c:\Users\Dan\newfolder\filename1)
    
    Set noAttachment = noDocument.CreateRichTextItem("c:\Users\Dan\newfolder\filename2")
    
      Set noEmbedObject = noAttachment.EmbedObject(EMBED_ATTACHMENT, "", c:\Users\Dan\newfolder\filename2)
    thanks

  5. #5
    Forum Contributor
    Join Date
    08-04-2010
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    143

    Re: vba to send email and attachments via lotus 8.5

    can anybody ans my qn? thanks

  6. #6
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: vba to send email and attachments via lotus 8.5

    To answer your questions:

    1. No change should be necessary because Session.UserName should be your user name. Verify this by stepping through the code in the debugger.

    2 and 3. In your posted code the Attachment variable is a string containing the full path and filename of an attachment, so this is the part you need to change. You'll also need to specify a unique rich text item name for each attached file. For example:
            Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment1")
            Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", "C:\file.jpg", "Attachment")
    
            Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment2")
            Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", "C:\file.pdf", "Attachment")
    Last edited by Chippy; 10-31-2010 at 10:54 AM.

  7. #7
    Forum Contributor
    Join Date
    08-04-2010
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    143

    Re: vba to send email and attachments via lotus 8.5

    i shall try that tomorrow when i have access to lotus. thanks
    Last edited by dan2010; 11-01-2010 at 08:34 AM.

  8. #8
    Forum Contributor
    Join Date
    08-04-2010
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    143

    Re: vba to send email and attachments via lotus 8.5

    it works perfectly. thank you

  9. #9
    Registered User
    Join Date
    02-20-2014
    Location
    London,England
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: vba to send email and attachments via lotus 8.5

    That helped me as well, thank you

  10. #10
    Registered User
    Join Date
    01-19-2015
    Location
    Farnham, England
    MS-Off Ver
    2010
    Posts
    1

    Re: vba to send email and attachments via lotus 8.5

    Well, that saved me some time, thanks for that

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1