Function send_mail (you_account, you_password, send_email, send_email2, send_topic, send_body, send_attachment)
'Code by netpatch
'Vbs mail sending parameter descriptions
'You _ account': Your email account
'You _ password: Your Email Password
'Send _ Email: main email address
'Send _ email2: alternate email address
'Send _ TOPIC: Email Subject
'Send _ body: Mail content
'Send _ attachment: email attachment
You_id = Split (you_account, "@",-1, vbtextcompare)
'Account and server Separation
Ms_space = "http://schemas.microsoft.com/cdo/configuration"
'This is a must, but you can rest assured that you will not send emails through Microsoft.
Set email = Createobject ("CDO. Message ")
Email. From = you_account
'This must be the same as the email sending account.
Email. To = send_email 'main email address
If send_email2 <> "then
Email. Cc = send_email2 'backup email address
End if
Email. Subject = send_topic 'subject
Email. textbody = send_body 'email content
If send_attachment <> "" then
Email. addattachment send_attachment 'email attachment
End if
With email. configuration. Fields
. Item (ms_space & "sendusing") = 2' mail port
. Item (ms_space & "smtpserver") = "SMTP." & you_id (1) 'smtp server address
. Item (ms_space & "smtpserverport") = 25 'smtp server port
. Item (ms_space & "smtpauthenticate") = 1' cdobasec
. Item (ms_space & "sendusername") = you_id (0) 'your email account
. Item (ms_space & "sendpassword") = you_password 'Your Email Password
. Update
End
Email. Send
'Send email
Set email = nothing
'Close the component
Send_mail = true
'If no error message exists, the message is sent successfully. Otherwise, the message fails to be sent.
If err then
Err. Clear
Send_mail = false
End if
End Function
below is an example of sending an email with an attachment using the above function
If send_mail ("test@163.com", "test", "test2@163.com ","", "Email Subject", "email content", "d: \ test.exe") = true then
wscript. echo "sent successfully"
else
wscript. echo "failed to send"
end if