Code of sending mail by CDO. Message in vbs

Time:2019-12-21

CDO. Message object can be used to implement. The example code demonstrates the mail sent by Gmail in plain text with attachments. As for other e-mails, the corresponding SMTP server and port in the code need to be modified. The principle is the same, so there is no example. The posted code did not write a comment. Please download the source code if you need to see the comment.

Copy codeThe code is as follows:
Const Email_From = “[email protected]
Const Password = “password”
Const Email_To = “[email protected]
Set CDO = CreateObject(“CDO.Message”)
CDO.Subject = “From Demon”
CDO.From = Email_From
CDO.To = Email_To
CDO.TextBody = “Hello world!”
cdo.AddAttachment = “C:\hello.txt”
Const schema = “http://schemas.microsoft.com/cdo/configuration/”
With CDO.Configuration.Fields
.Item(schema & “sendusing”) = 2
.Item(schema & “smtpserver”) = “smtp.gmail.com”
.Item(schema & “smtpauthenticate”) = 1
.Item(schema & “sendusername”) = Email_From
.Item(schema & “sendpassword”) = Password
.Item(schema & “smtpserverport”) = 465
.Item(schema & “smtpusessl”) = True
.Item(schema & “smtpconnectiontimeout”) = 60
.Update
End With
CDO.Send

Detailed Notes version:

Copy codeThe code is as follows:
‘Date: 2010/6/18
‘Author: Demon
‘QQ: 380401911
‘E-mail: [email protected]
‘Website: http://demon.tw

Const email from = “DDD @ 163. Com”
Const password = “password” ‘sender’s email password
Const email to = “380401911 @ QQ. Com” ‘

Set CDO = CreateObject (“CDO. Message”) ‘create CDO. Message object
Cdo.subject = “from demon” ‘mail subject
Cdo.from = email “from” sender address
CDO. To = email_to ‘recipient address
Cdo.textbody = “Hello world!” ‘message body
Cdo.addattachment = “C: \ hello. TXT” ‘mail attachment file path
Const schema = “http://schemas.microsoft.com/cdo/configuration / ‘the rule must be this, and I don’t know why

With CDO. Configuration. Fields’ use with keyword to reduce code input
. item (schema & “sending”) = 2 ‘use the SMTP server on the network instead of the local SMTP server
. item (schema & “SMTP server”) = “SMTP. Gmail. Com”‘smtp server address
. item (schema & “smtpauthenticate”) = 1 ‘server authentication method
. item (schema & “sendusername”) = email from ‘sender email
. item (schema & “sendpassword”) = password ‘sender email password
. item (schema & “SMTP server port”) = 465 ‘SMTP server port
. item (schema & “smtpusessl”) = true ‘use SSL or not
. item (schema & “smtpconnectiontimeout”) = 60 ‘timeout for connecting to the server
. update ‘update settings
End With

CDO. Send ‘send mail

Original: http://demon.tw/programming/vbs-send-email.html