functionSend_mail(You_Account,You_Password,Send_Email,Send_Email2,Send_Topic,Send_Body,Send_Attachment)
'codebyNetPatch
'VBS发送邮件参数说明
'You_Account:你的邮件帐号
'You_Password:你的邮件密码
'Send_Email:主要邮件地址
'Send_Email2:备用邮件地址
'Send_Topic:邮件主题
'Send_Body:邮件内容
'Send_Attachment:邮件附件
You_ID=Split(You_Account,"@",-1,vbTextCompare)
'帐号和服务器分离
MS_Space="http://schemas.microsoft.com/cdo/configuration/"
'这个是必须要的,不过可以放心的事,不会通过微软发送邮件
SetEmail=CreateObject("CDO.Message")
Email.From=You_Account
'这个一定要和发送邮件的帐号一样
Email.To=Send_Email'主要邮件地址
IfSend_Email2<>""Then
Email.CC=Send_Email2'备用邮件地址
EndIf
Email.Subject=Send_Topic'邮件主题
Email.Textbody=Send_Body'邮件内容
IfSend_Attachment<>""Then
Email.AddAttachmentSend_Attachment'邮件附件
EndIf
WithEmail.Configuration.Fields
.Item(MS_Space&"sendusing")=2'发信端口
.Item(MS_Space&"smtpserver")="smtp."&You_ID(1)'SMTP服务器地址
.Item(MS_Space&"smtpserverport")=25'SMTP服务器端口
.Item(MS_Space&"smtpauthenticate")=1'cdobasec
.Item(MS_Space&"sendusername")=You_ID(0)'你的邮件帐号
.Item(MS_Space&"sendpassword")=You_Password'你的邮件密码
.Update
EndWith
Email.Send
'发送邮件
SetEmail=Nothing
'关闭组件
Send_Mail=True
'如果没有任何错误信息,则表示发送成功,否则发送失败
IfErrThen
Err.Clear
Send_Mail=False
EndIf
EndFunction
'以下是利用上面的函数发送带附件的邮件例子
IfSend_Mail("test@163.com","test","test2@163.com","","邮件主题","邮件内容","d:test.exe")=TrueThen
Wscript.Echo"发送成功"
Else
Wscript.Echo"发送失败"
EndIf