MailSender

MailSender用于通过SMTP服务器发送邮件。

属性:

方法:

示例一

Dim m As New MailSender
m
.Host = "smtp.21cn.net"
m
.Account = "xiaoliu"
m
.Password = "xiaoliu1234567"
m
.From = "xiaoliu@Sina.com.cn"
m
.To = "meili@Sina.com.cn"
m
.Title = "李总明天来北京"
m
.Content = "航班号是gz1234,上午11点到达,请注意接机"
m.SendAsync()

示例一

如果接收方出现邮件内容乱码,可以明确指定邮件内容编码,例如用UTF8编码邮件内容:

Dim m As New MailSender
m
.Host = "smtp.21cn.net"
m
.Account = "xiaoliu"
m
.Password = "xiaoliu1234567"
m
.From = "xiaoliu@Sina.com.cn"
m
.To = "meili@Sina.com.cn"
m.Encoding = Encoding.UTF8
m
.Title = "李总明天来北京"
m
.Content = "航班号是gz1234,上午11点到达,请注意接机"
m.SendAsync()

示例三

可以同时添加多个收件人:

Dim m As New MailSender
m
.Host = "smtp.21cn.net"
m
.Account = "xiaoliu"
m
.Password = "xiaoliu1234567"
m
.From = "xiaoliu@Sina.com.cn"
m.AddReceiver(
"meili@Sina.com.cn")
m.AddReceiver(
"yangzi@Microsoft.com")
m.Title =
"李总明天来北京"
m
.Content = "航班号是gz1234,上午11点到达,请注意接机"
m.SendAsync()

示例四

还可以加入附件:

Dim m As New MailSender
m
.Host = "smtp.21cn.net"
m
.Account = "xiaoliu"
m
.Password = "xiaoliu1234567"
m
.From = "xiaoliu@Sina.com.cn"
m.
To = "meili@Sina.com.cn"
m.Title =
"初稿已经完成"
m.Content =
"附件为初稿, 请您审阅!"
m.AddAttachments(
"c:\data\table.txt")
m.SendAsync()

示例五

有了MailSender,我们可以根据数据表内容动态合成邮件发送,例如下面的代码从借款表中筛选出10天内到期的客户,并发送催款邮件:

Dim m As New MailSender
Dim
ln As String = vbcrlf & vbcrlf '定义两个换行

m.Host =
"smtp.21cn.net"
m.Account =
"xiaoliu"
m.Password =
"xiaoliu1234567"
m.From =
"xiaoliu@Sina.com.cn"
For Each
dr As DataRow In DataTables("借款").Select("到期日期<= #" & Date.Today.AddDays(10) & "#")
    m
.To = dr("邮件地址"
)
    m
.Title =
"催款通知"
   
m.Content = dr("姓名") & dr("尊称") & ":" & ln & "您的贷款将于" & dr("到期日期") & "到期, "
    m
.Content = m.Content & "金额为" & dr("金额") & "元, 请准时还款!" & ln & "某某公司" & vbcrlf & Date.
today
    m.SendAsync()

Next

 

 


本页地址:http://www.foxtable.com/webhelp/topics/1404.htm