以下代码由 HK1 发布,以响应 2012 年 7 月 20 日在 VBA 中发送没有 Outlook 的电子邮件的答案。
代码运行良好,但我需要在文本末尾添加一个签名块(基本上是本地文件夹中的 jpg 文件),但我能想到的最好的方法是添加路径(文本)图像本身的电子邮件正文。
Const cdoSendUsingPickup = 1
Const cdoSendUsingPort = 2
Const cdoAnonymous = 0
' Use basic (clear-text) authentication.
Const cdoBasic = 1
' Use NTLM authentication
Const cdoNTLM = 2 'NTLM
Public Sub SendEmail()
Dim imsg As Object
Dim iconf As Object
Dim flds As Object
Dim schema As String
Set imsg = CreateObject("CDO.Message")
Set iconf = CreateObject("CDO.Configuration")
Set flds = iconf.Fields
' send one copy with SMTP server (with autentication)
schema = "http://schemas.microsoft.com/cdo/configuration/"
flds.Item(schema & "sendusing") = cdoSendUsingPort
flds.Item(schema & "smtpserver") = "mail.myserver.com"
flds.Item(schema & "smtpserverport") = 25
flds.Item(schema & "smtpauthenticate") = cdoBasic
flds.Item(schema & "sendusername") = "email@email.com"
flds.Item(schema & "sendpassword") = "password"
flds.Item(schema & "smtpusessl") = False
flds.Update
With imsg
.To = "email@email.com"
.From = "email@email.com"
.Subject = "Test Send"
.HTMLBody = "Test"
'.Sender = "Sender"
'.Organization = "My Company"
'.ReplyTo = "address@mycompany.com"
Set .Configuration = iconf
.Send
End With
Set iconf = Nothing
Set imsg = Nothing
Set flds = Nothing
End Sub
我尝试按如下方式修改代码,但这只是将文件路径添加到正文中:
With imsg
.To = vRecipients
.From = senderEmail
.CC = vCC
.Subject = vSubject
vBody = Replace(vBody, vbCrLf, "<br>")
vBody = "<FONT face=arial size=2>" & vBody
vBody = vBody & "<br>" & signFile
.HTMLBody = vBody
.Sender = senderName
.ReplyTo = senderEmail
.AddAttachment vAttachments
Set .Configuration = iconf
.Send
End With
有什么建议么?