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