我目前正在使用 CDO 透過 VBA 使用 SMTP 從 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