Implementation code for sending mail with Cdo.message in VBS _vbs

Source: Internet
Author: User
Tags comments server port
Using the Cdo.message object can be implemented, the sample code demonstrates that Gmail sent plain text and with the attachment of the mail, as for other e-mail, need to modify the corresponding SMTP server and port in the code, the principle is the same, no example. Posted code does not write comments, you need to see the comments download source.
Copy Code code as follows:

Const email_from = "still.demon@gmail.com"
Const Password = "Password"
Const email_to = "380401911@qq.com"
Set CDO = CreateObject ("CDO.") Message ")
Cdos. Subject = "from Demon"
Cdos. From = Email_from
Cdos. to = Email_to
Cdos. TextBody = "Hello world!"
Cdos. AddAttachment = "C:\hello.txt"
Const schema = "http://schemas.microsoft.com/cdo/configuration/"
With CDOs. 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
Cdos. Send

Detailed Comment version:
Copy Code code 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 mailbox password
Const email_to = "380401911@qq.com" Recipient mailbox

Set CDO = CreateObject ("CDO.") Message ")" Creates a Cdo.message object
Cdos. Subject = "from Demon" ' Message subject
Cdos. from = Email_from ' Sender address
Cdos. to = Email_to ' recipient address
Cdos. TextBody = "Hello world!" ' Message body
Cdos. AddAttachment = "C:\hello.txt" ' Mail attachment file path
Const schema = "http://schemas.microsoft.com/cdo/configuration/" ' rules must be this, and I don't know why

With CDOs. Configuration.fields ' use with keyword to reduce code input
. Item (Schema & "sendusing") = 2 ' Use an SMTP server on the network instead of a 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 mailbox password
. Item (Schema & "smtpserverport") = 465 ' SMTP server port
. Item (Schema & "Smtpusessl") = True ' Whether SSL is used
. Item (Schema & "smtpconnectiontimeout") = 60 ' timeout for connecting to the server
. Update ' Updates settings
End With

Cdos. Send ' sending mail

Original: 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.