VBScript - 确认已收到电子邮件的最佳方式

时间:2017-10-29 06:25:27

标签: vbscript

我使用此基本vbscript代码向某人发送了一封电子邮件,但效果很好,但我想确认已收到该电子邮件。 有没有办法做到这一点? 我用来发送邮件的代码是:

Dim objMessage 'object mail

Set objMessage = CreateObject("CDO.Message") 
objMessage.BodyPart.Charset = "utf-8"
objMessage.Subject = subjectStr
objMessage.From = "To someone"
objMessage.To = toWhoStr
objMessage.TextBody = contentStr 
objMessage.AddAttachment AttachmentFile

'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "ip smtp server"

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1'cdoBasic


'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587

'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = false

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send

Set ObjMessage = Nothing

更新我更新了我的代码,现在我收到了一些电子邮件的通知。

Const CDO_SUCCESS = 4 ' sends delivery receipt if succesfull 
Const CDO_FAIL = 2 ' sends delivery receipt if fails 
Const CDO_DELAY = 8 ' sends delivery receipt if delayed 
Const CDO_SUCCESS_FAIL_DELAY = 14 ' sends delivery receipt always 

Dim objMessage 'object mail
Dim iConf
Dim Flds
    Set objMessage = CreateObject("CDO.Message")  

    set iconf = createobject("cdo.configuration") 
    Set Flds = iConf.Fields 
    With Flds 
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "ip smtp server" 
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1'cdoBasic
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
    .Update 
    End With 
    '==End remote SMTP server configuration section==

    With objMessage
        .BodyPart.Charset = "utf-8"
        Set .Configuration = iConf 
        .To = toWhoStr 
        .From = "from who" 
        .Subject = "BLA BLA BLA" 
        .TextBody = "PING PONG" 
        .fields("urn:schemas:mailheader:disposition-notification-to") = "email to notification" 
        .fields("urn:schemas:mailheader:return-receipt-to") = "email to notification"
        .DSNOptions = 14 
        .fields.update
        .Send
    End With 
    Set ObjMessage = Nothing

使用此代码,当发送给他的邮件的用户打开邮件并尝试关闭邮件然后打开弹出窗口,询问他是否要通知他收到邮件。

我没有找到自动发送通知的方式。

1 个答案:

答案 0 :(得分:3)

请看下面的链接,它应该指向正确的方向。

Send CDO Mail with Read and Delivery Receipts

利。