VBS通过SMTP发送邮件

本文介绍如何利用Visual Basic Script (VBS)配合SMTP服务器发送电子邮件,涉及基本的SMTP认证和SSL连接设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

mfrom="abcd@abcd.com" rcpt="abcd@abcd.com, abcd@abcd.com" attachfile=null serverip="smtp.abcd.com" sbj="Subject" tbody="Hello World" Call SendMail(mfrom,rcpt,sbj,tbody,attachfile,serverIP)

 

Sub SendMail (mfrom,rcpt,sbj,tbody,attachfile,serverIP)
'######### call SendMail (mfrom,rcpt,cc,sbj,tbody,serverIP) ##################
'Use external smtp server to send mail
if trim(rcpt) = "" or trim(mfrom) = "" then
        exit sub
end if

On Error Resume Next
  Set objEmail = CreateObject("CDO.Message")
  objEmail.From = mfrom
  objEmail.To = rcpt
'  objEmail.Cc = cc
'  objEmail.Bcc = bcc
  objEmail.Subject = sbj
  objEmail.Textbody = tbody
'Sending an HTML e-mail:
'  objEmail.HTMLBody = "
This is a message.

"
'Sending an HTML e-mail that sends a webpage from a website:
'  objEmail.CreateMHTMLBody "file://c:/mydocuments/test.htm"
  If Trim(attachfile) <> "" Then objEmail.AddAttachment attachfile
  objEmail.Configuration.Fields.Item _
   ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  objEmail.Configuration.Fields.Item _
   ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = serverIP
  objEmail.Configuration.Fields.Item _
   ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'-------Type of authentication, NONE, Basic (Base64 encoded), NTLM--------
'objEmail.Configuration.Fields.Item _
'("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
'-------Your UserID/Passwd on the SMTP server for SMTP auth for mail sent-----
'objEmail.Configuration.Fields.Item _
'("http://schemas.microsoft.com/cdo/configuration/sendusername") = "USER_NAME"
'objEmail.Configuration.Fields.Item _
'("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "PASSWORD"
'-------Use SSL for the connection (False or True)---------
'objEmail.Configuration.Fields.Item _
'("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
'Connection Timeout in seconds (the maximum time CDO will try to establish a
'--------connection to the SMTP server)---------
'objEmail.Configuration.Fields.Item _
'("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

  objEmail.Configuration.Fields.Update
  objEmail.Send
  set objEmail=nothing
End Sub

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值