Sending email with attachment by vbs


function Send_mail(You_Account,You_Password,Send_Email,Send_Email2,Send_Topic,Send_Body,Send_Attachment) 
‘code by NetPatch
‘VBS send mail parameter description
‘You_ Account: your email account number
‘You_ Password: your email password
‘Send_ Email: primary email address
‘Send_ Email 2: alternate email address
‘Send_ Topic: email subject
‘Send_ Body: message content
‘Send_ Attachment: mail attachment

You_ID=Split(You_Account, “@”, -1, vbTextCompare) 
‘the account and the server are separated
MS_Space = “”
‘This is a must, but you can rest assured that you won’t send email through Microsoft
Set Email = CreateObject(“CDO.Message”)
Email.From = You_Account
‘This must be the same as the account that sent the email
Email.To  = Send_ Email ‘primary email address

If Send_Email2 <> “” Then
Email.CC  = Send_ Email 2 ‘alternate email address
End If

Email.Subject  = Send_ Topic ’email subject
Email.Textbody  = Send_ Body ’email content

If Send_Attachment <> “” Then
Email.AddAttachment  Send_ Email attachment
End If

With Email.Configuration.Fields
.Item(MS_ Space & sending “) = 2 ‘sending 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_ Your email password
End With
‘Send the message
Set Email=Nothing
‘close the component

‘if there is no error message, the sending is successful, otherwise the sending fails
If Err Then 
End If 
End Function

‘the following is an example of sending an email with attachments using the above function
If Send_ Mail(” [email protected] “,”test”,” [email protected] “Message subject”, “message content”, “D:\ test.exe “)=True Then
Wscript.Echo “Sent successfully”
Wscript.Echo “Send failed”
End If