用vbs发送带附件的邮件
程序员文章站
2022-07-04 20:47:35
function send_mail(you_account,you_password,send_email,send_email2,send_topic,sen...
function send_mail(you_account,you_password,send_email,send_email2,send_topic,send_body,send_attachment)
'code by netpatch
'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/"
'这个是必须要的,不过可以放心的事,不会通过微软发送邮件
set email = createobject("cdo.message")
email.from = you_account
'这个一定要和发送邮件的帐号一样
email.to = send_email '主要邮件地址
if send_email2 <> "" then
email.cc = send_email2 '备用邮件地址
end if
email.subject = send_topic '邮件主题
email.textbody = send_body '邮件内容
if send_attachment <> "" then
email.addattachment send_attachment '邮件附件
end if
with email.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
end with
email.send
'发送邮件
set email=nothing
'关闭组件
send_mail=true
'如果没有任何错误信息,则表示发送成功,否则发送失败
if err then
err.clear
send_mail=false
end if
end function
'以下是利用上面的函数发送带附件的邮件例子
if send_mail("test@163.com","test","test2@163.com","","邮件主题","邮件内容","d:\test.exe")=true then
wscript.echo "发送成功"
else
wscript.echo "发送失败"
end if
'code by netpatch
'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/"
'这个是必须要的,不过可以放心的事,不会通过微软发送邮件
set email = createobject("cdo.message")
email.from = you_account
'这个一定要和发送邮件的帐号一样
email.to = send_email '主要邮件地址
if send_email2 <> "" then
email.cc = send_email2 '备用邮件地址
end if
email.subject = send_topic '邮件主题
email.textbody = send_body '邮件内容
if send_attachment <> "" then
email.addattachment send_attachment '邮件附件
end if
with email.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
end with
email.send
'发送邮件
set email=nothing
'关闭组件
send_mail=true
'如果没有任何错误信息,则表示发送成功,否则发送失败
if err then
err.clear
send_mail=false
end if
end function
'以下是利用上面的函数发送带附件的邮件例子
if send_mail("test@163.com","test","test2@163.com","","邮件主题","邮件内容","d:\test.exe")=true then
wscript.echo "发送成功"
else
wscript.echo "发送失败"
end if