2

I am trying to trigger a macro which will send an email when a user updates my cell in column N.

The email has to be sent using IBM notes. The code below, sends the email fine. However, i am not familiar with IBM notes and i am wanting to try and format my email as HTML.

At the moment, the email is sending plain text.

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("M:M")) Is Nothing Then
    If Target.Cells.Count < 3 Then



  '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)
    Dim Ref As String
    Dim TrueRef As String


    Ref = Range("H" & (ActiveCell.Row)).Value

    If Ref = "WSM" Then
    TrueRef = "WES"
    Else
    If Ref = "NAY" Then
    TrueRef = "NAY"
    Else
    If Ref = "ENF" Then
    TrueRef = "ENF"
    Else
    If Ref = "LUT" Then
    TrueRef = "MAG"
    Else
    If Ref = "NFL" Then
    TrueRef = "NOR"
    Else
    If Ref = "RUN" Then
    TrueRef = "RUN"
    Else
    If Ref = "SOU" Then
    TrueRef = "SOU"
    Else
    If Ref = "SOU" Then
    TrueRef = "SOU"
    Else
    If Ref = "BRI" Then
    TrueRef = "BRI"
    Else
    If Ref = "LIV" Then
    TrueRef = "LIV"
    Else
    If Ref = "BEL" Then
    TrueRef = "BEL"
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If




    '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.Principal = "Food.Specials@inbox.co.uk"
    MailDoc.ReplyTo = "Food.Specials@inbox.co.uk"
    'MailDoc.DisplaySent = "Food.Specials@inbox.co.uk"
    'MailDoc.iNetFrom = "Food.Specials@inbox.co.uk"
    'MailDoc.iNetPrincipal = "Food.Specials@inbox.co.uk"
    MailDoc.Form = "Memo"
    MailDoc.sendto = "Supplychain-" & TrueRef & "@inbox.co.uk"
    MailDoc.subject = "L.O. Delivery Tracker: The status of your Issue has been updated."





    MailDoc.HTMLbody = "<html><body><p>Hello</p><p>Please find attached the above invoices and backup.</p>" _
     & "<p>Any queries please let me know</p><p>Regards</p>" & Signature & "</body></html>"
    MailDoc.SAVEMESSAGEONSEND = SaveIt



    '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 If
End If

End Sub

Please can someone show me what i need to do to get this email to send as html? Thanks

Princess.Bell
  • 333
  • 1
  • 5
  • 26

1 Answers1

1

First of all, you may want to be using a Lotus.NotesSession object instead of the Notes.NotesSession object. The Notes.NotesSession class uses OLE, which requires that the Notes client must be running whenever you invoke it. The Lotus.NotesSession class uses COM, which doens't require that the Notes client is running - though it must be installed.

As for sending HTML mail via Notes APIs, you can refer to this IBM Technote. The language used in that note is LotusScript, but the concepts and classes are the same, and the syntax is quite similar to VBA. The one thing I'm uncertain of is whether the NotesStream class that it uses is exposed through the COM API. (Also, see this answer to a previous StackOverflow question. The comments there indicate that the NotesStream class was not available, but the questioner in that case also used the OLE classes, not the COM classes.)

Community
  • 1
  • 1
Richard Schwartz
  • 13,485
  • 2
  • 21
  • 39