简体   繁体   English

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

[英]Excel VBA: Send HTML email using IBM Notes

I am trying to trigger a macro which will send an email when a user updates my cell in column N.我正在尝试触发一个宏,该宏将在用户更新 N 列中的单元格时发送电子邮件。

The email has to be sent using IBM notes.必须使用 IBM 笔记发送电子邮件。 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.但是,我不熟悉 IBM 笔记,我想尝试将我的电子邮件格式化为 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?请有人告诉我我需要做什么才能让这封电子邮件以 html 格式发送吗? Thanks谢谢

First of all, you may want to be using a Lotus.NotesSession object instead of the Notes.NotesSession object.首先,您可能希望使用 Lotus.NotesSession 对象而不是 Notes.NotesSession 对象。 The Notes.NotesSession class uses OLE, which requires that the Notes client must be running whenever you invoke it. Notes.NotesSession 类使用 OLE,它要求无论何时调用 Notes 客户端都必须运行。 The Lotus.NotesSession class uses COM, which doens't require that the Notes client is running - though it must be installed. Lotus.NotesSession 类使用 COM,它不需要 Notes 客户端正在运行——尽管必须安装它。

As for sending HTML mail via Notes APIs, you can refer to this IBM Technote .关于通过 Notes API 发送 HTML 邮件,可以参考这篇 IBM 技术说明 The language used in that note is LotusScript, but the concepts and classes are the same, and the syntax is quite similar to VBA.该注释中使用的语言是 LotusScript,但概念和类相同,语法与 VBA 非常相似。 The one thing I'm uncertain of is whether the NotesStream class that it uses is exposed through the COM API.我不确定的一件事是它使用的 NotesStream 类是否通过 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.) (另外,请参阅上一个 StackOverflow 问题的答案。那里的评论表明 NotesStream 类不可用,但在这种情况下,提问者也使用了 OLE 类,而不是 COM 类。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM