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