发送附有文本文件的电子邮件,这有效(收到测试电子邮件):
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "sender@domain.tld"
emailObj.To = "recipient@domain.tld"
emailObj.Subject = "File attached"
emailObj.TextBody = "Please have a look at the attached file. Thanks."
emailObj.AddAttachment "d:\temp\test.txt"
Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "server.webhost.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "sender@domain.tld"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "top_secret"
emailConfig.Fields.Update
emailObj.Send
If err.number = 0 then Msgbox "Your file has been sent. Someone will respond as soon as possible."
但是当我尝试发送二进制文件时,这不起作用(未收到测试电子邮件):
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "sender@domain.tld"
emailObj.To = "recipient@domain.tld"
emailObj.Subject = "File attached"
emailObj.TextBody = "Please have a look at the attached file. Thanks."
emailObj.AddAttachment "d:\temp\test.rtf"
Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "server.webhost.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "sender@domain.tld"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "top_secret"
emailConfig.Fields.Update
emailObj.Send
If err.number = 0 then Msgbox "Your file has been sent. Someone will respond as soon as possible."
我需要添加/更改哪些内容才能附加二进制文件?