![使用 VBA 从 MSAccess 发送电子邮件](https://linux22.com/image/1520299/%E4%BD%BF%E7%94%A8%20VBA%20%E4%BB%8E%20MSAccess%20%E5%8F%91%E9%80%81%E7%94%B5%E5%AD%90%E9%82%AE%E4%BB%B6.png)
我目前正在使用 CDO 通过 SMTP 从带有 VBA 的 Access 发送电子邮件,并且运行良好。
我的问题是,当我使用 SMTP 时,我在使用的邮箱的已发送邮件中看不到已发送的电子邮件。我需要这个,以便我可以向收件人证明电子邮件确实已发送。有人知道我该如何解决这个问题吗?欢迎提供 、 或 (如上所述)中的任何解决方案。下面是VB.NET
我C#
的VBScript
脚本。VBA
VBA
Const cdoSendUsingPickup = 1
Const cdoSendUsingPort = 2 'Must use this to use Delivery Notification
Const cdoAnonymous = 0
Const cdoBasic = 1 ' clear text
Const cdoNTLM = 2 'NTLM
'Delivery Status Notifications
Const cdoDSNDefault = 0 'None
Const cdoDSNNever = 1 'None
Const cdoDSNFailure = 2 'Failure
Const cdoDSNSuccess = 4 'Success
Const cdoDSNDelay = 8 'Delay
Const cdoDSNSuccessFailOrDelay = 14 'Success, failure or delay
Set objmsg = CreateObject("CDO.Message")
Set objConf = CreateObject("CDO.Configuration")
Set objFlds = objConf.Fields
With objFlds
''http://schemas.microsoft.com/cdo/configuration/ the .Items must pe prefixed with this
.Item("sendusing'") = cdoSendUsingPort
.Item("smtpserver'") = "1.1.1.1"
.Item("smtpauthenticate") = cdoBasic
.Item("sendusername") = Username
.Item("sendpassword") = Password
.Item("smtpserverport") = 25
.Update
End With
strbody = "Message here"
With objmsg
Set .Configuration = objConf
.To = "[email protected]"
.From = "[email protected]"
.Subject = "EmailSubject"
.HTMLBody = strBody
.AddAttachment myfile
.Fields("urn:schemas:mailheader:disposition-notification-to") = "[email protected]"
.DSNOptions = cdoDSNSuccessFailOrDelay
.Fields.Update
.Send
If Err.Number <> 0 Then
Debug.Print Err.Description
End If