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

我试图触发一个macros,当用户更新列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 = "LO 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? 谢谢

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

至于通过Notes API发送HTML邮件,您可以参考这个IBM Technote 。 该笔记中使用的语言是LotusScript,但概念和类是相同的,语法与VBA非常相似。 我不确定的一件事是它使用的NotesStream类是否通过COM API公开。 (另外,请参阅前面的StackOverflow问题的答案,其中的注释表示NotesStream类不可用,但在这种情况下,提问者也使用OLE类,而不是COM类。