//其中Addr为目标对象的email地址,MessageText为邮件内容
ClassMethod SendEmail(Addr As %Library.String,
MessageText As %Library.String)
As %Library.String
{
New Mailer,Msg
// Create an SMTP object and connect to a server
Set Mailer =
##class(%Net.SMTP).%New()
// Fill in the name of your mail server
Set Mailer.smtpserver =
"SMTP.qq.com"//设置smtpserver,本例使用Tencent的qq邮箱,注意qq邮箱需要开通smtp
Set Mailer.port="25"
set Author =
##class(%Net.Authenticator).%New()设置授权
set Author.UserName="发件人的email地址"
set Author.Password="发件人的email密码"
set Mailer.authenticator =
Author
// Create a Message object and fill in From, To, Subject
Set Msg =
##class(%Net.MailMessage).%New()
// Fill in an email address
Set Msg.From="发件人的email地址"
Do Msg.Cc.Insert("添加抄送对象的email地址,可实现发送给多人")
Do Msg.To.Insert(Addr)
Set Msg.Subject =
"邮件标题"//设置邮件标题
// Add message content
Do Msg.TextData.Write("hi,this
is a email")
// Send the message and close objects
Do Mailer.Send(Msg)
Quit "Email confirmation has been sent to " _
Addr
}
本文将介绍如何利用VBScript代码实现发送邮件至指定邮箱的功能,包括配置SMTP服务器、填写邮件信息、添加附件等步骤,适用于需要自动化邮件发送场景。

被折叠的 条评论
为什么被折叠?



