Excel VBA:使用IBM Notes发送HTML电子邮件

时间:2017-01-09 11:21:40

标签: excel vba email lotus-notes lotus

我正在尝试触发一个宏,当用户在N列中更新我的单元格时,该宏将发送电子邮件。

必须使用IBM笔记发送电子邮件。 下面的代码,发送电子邮件很好。但是,我不熟悉IBM笔记,我想尝试将我的电子邮件格式化为HTML。

目前,电子邮件正在发送纯文本。

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

请有人告诉我我需要做什么才能将此电子邮件发送为html?感谢

1 个答案:

答案 0 :(得分:1)

首先,您可能希望使用Lotus.NotesSession对象而不是Notes.NotesSession对象。 Notes.NotesSession类使用OLE,这要求必须在调用Notes客户端时运行它。 Lotus.NotesSession类使用COM,尽管必须安装它,但它并不需要Notes客户端运行。

对于通过Notes API发送HTML邮件,您可以参考fillna。该注释中使用的语言是LotusScript,但概念和类是相同的,语法与VBA非常相似。我不确定的一件事是它使用的NotesStream类是否通过COM API公开。 (另请参阅此this IBM Technote。那里的注释表明NotesStream类不可用,但该案例中的提问者也使用了OLE类,而不是COM类。)