Implementation Code of sending emails using CDO. Message in VBS

Source: Internet
Author: User

Use CDO. the Message object can be implemented. The example code demonstrates mail sent by gmail in plain text with attachments. For other email addresses, You need to modify the corresponding smtp server and port in the code, the same is true. The posted code does not contain comments. If you need to read the comments, download the source code. Copy codeThe Code is as follows: Const Email_From = "still.demon@gmail.com"
Const Password = "password"
Const Email_To = "380401911@qq.com"
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
CDO. Send

Comments:Copy codeThe Code is as follows: 'date: 2010/6/18
'Author: Demon
'Qq: 380401911
'E-mail: still.demon@gmail.com
'Website: http://demon.tw

Const Email_From = "ddd@163.com" 'sender's mailbox
Const Password = "password" 'sender's email Password
Const Email_To = "380401911@qq.com" 'recipient mailbox

Set CDO = CreateObject ("CDO. Message") 'creates a CDO. Message object.
CDO. Subject = "From Demon" 'Email Subject
CDO. From = Email_From 'sender address
CDO. To = Email_To 'recipient address
CDO. TextBody = "Hello world! "'Mail body
Cdo. AddAttachment = "C: \ hello.txt" 'email attachment file path
Const schema = "http://schemas.microsoft.com/cdo/configuration/" 'specifies that it must be this, and I don't know why

With CDO. Configuration. Fields use the with keyword to reduce code input.
. Item (schema & "sendusing") = 2' use the SMTP server on the network instead of the local SMTP Server
. Item (schema & "smtpserver") = "smtp.gmail.com" 'smtp server address
. Item (schema & "smtpauthenticate") = 1' Server Authentication Method
. Item (schema & "sendusername") = Email_From 'sender's mailbox
. Item (schema & "sendpassword") = Password 'sender's email Password
. Item (schema & "smtpserverport") = 465 'smtp server port
. Item (schema & "smtpusessl") = true' whether to use SSL
. Item (schema & "smtpconnectiontimeout") = 60 'timeout time for connecting to the server
. Update' Update settings
End

CDO. Send 'send mail

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.