如何发送带有多个附件的电子邮件

时间:2019-11-12 11:34:49

标签: vbscript

只要每个文件都在该代码中,该代码就可以正常工作。 即使文件丢失,发送电子邮件的代码中缺少什么? 我试图找到一种解决方案,但没有成功。

Set fso=CreateObject("Scripting.FileSystemObject")

strSMTP="smtp.telenor.no"
strSubject="Files form me to you"
strSubject="XXXXX"
strSubject="XXXX"
strBody="XXXXXX"
strAttach="File 1.csv"
strAttach1="File 2.csv"
strAttach2="File 3.csv"

If fso.FileExists(strAttach) then
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1    ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTP
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    .Update
End With
With iMsg
    Set .Configuration = iConf
    .To = "XXXX"
    .CC = ""
    .BCC = ""
    .From = "XXXX"
    .Subject = strSubject
    .TextBody = strBody
    .AddAttachment strAttach
    .AddAttachment strAttach1
    .AddAttachment strAttach2
    .Send
End With
Set iMsg = Nothing
Set iConf = Nothing
Else
MsgBox "The specified attachment does not exist"
End if

1 个答案:

答案 0 :(得分:1)

以下内容使用ArrayList来保存您的附件,并将它们一个一个地添加到邮件中,检查文件是否首先存在:

variables:
- group: my-global
- name: env
  value:
    ${{ if eq(variables['Build.SourceBranchName'], 'master') }}: a
    ${{ if eq(variables['Build.SourceBranchName'], 'dev') }}: b