vba 从 IBM Notes 发送带有附件的电子邮件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23910155/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 03:17:35  来源:igfitidea点击:

Send email from IBM Notes with attachment

excelvbaemaillotus-notesattachment

提问by Stan

I'd like to send an email with an attachment using VBA and Lotus Notes. I manage to send an email but the attachment is never included. What am I missing here?

我想使用 VBA 和 Lotus Notes 发送带有附件的电子邮件。我设法发送了一封电子邮件,但从未包含附件。我在这里缺少什么?

Sub Macro1()
    ActiveWorkbook.Save

    Dim iMsg As Object
    Dim iConf As Object
    Dim strbody As String
    Dim fromAdr As String
    Dim subject As String
    Dim recip As String
    Dim numSend As Integer
    Dim Attachment1 As String

    ' Mail settings
    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")
    iConf.Load -1    ' CDO Source Defaults
    Set Flds = iConf.Fields

    ' Mail fields
    fromAdr = """[email protected]"
    recip = """[email protected]"
    Debug.Print strbody
    subject = "Orders fondsen"
    strbody = strbody & "Hi," & vbNewLine & vbNewLine & _
              "Please find the document..."

    ' Fields layout
    strbody = strbody & vbNewLine & vbNewLine & "Text"
    Debug.Print strbody
    strbody = strbody & vbNewLine & vbNewLine & "Kind regards,"

    ' Location attachment
    Attachment1 = "file-path"

    ' send mail
    On Error GoTo handleError
    With iMsg
        Set .Configuration = iConf
        .To = recip
        .CC = ""
        .From = fromAdr
        .subject = subject
        .TextBody = strbody
        .Send
    End With
    numSend = numSend + 1
    GoTo skipError

handleError:
    numErr = numErr + 1
    oFile.WriteLine "*** ERROR *** Email for account" & " not sent. Error: " & Err.Number & " " & Err.Description
skipError:

    On Error GoTo 0

    MsgBox "Total number of emails send: " & numSend & vbNewLine & "Total number of errors: " & numErr, vbOKOnly + vbInformation, "Operation finished"
    GoTo endProgram
cancelProgram:
    MsgBox "No emails have been sent.", vbOKOnly + vbExclamation, "Operation cancelled"

endProgram:
    Application.Interactive = True
    Set iMsg = Nothing
    Set iConf = Nothing
    Set dp = Nothing
End Sub

回答by parakmiakos

You need to add the attachment :

您需要添加附件:

With iMsg
   Set .Configuration = iConf
   .To = recip
   .CC = ""
   .From = fromAdr
   .subject = subject
   .TextBody = strbody
   .AddAttachment Attachment1 
   .Send
End With

You can repeat the .AddAttachmentfor each attachment you want to add.

您可以.AddAttachment为要添加的每个附件重复。