没有找到合适的产品?
联系客服协助选型:023-68661681
提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
翻译|使用教程|编辑:况鱼杰|2020-03-10 16:33:27.317|阅读 349 次
概述:本示例使用单个模板和数据库发送多封电子邮件。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
相关链接:
MailBee Objects是一个组件集合。您可以使用该控件创建并将邮件发送到SMTP服务器并从POP3服务器接收、解析以及删除电子邮件,还能在IMAP4服务器上管理电子邮件以及文件夹。它同样支持SSL以及S/MIME以获得更好的安全性能。MailBee控件能在ASP、VB、C++或任何支持ActiveX技术的语言中使用。
本示例使用单个模板和数据库发送多封电子邮件。
对于每个消息,从数据库中获取的实际值将替换模板中的占位符。因此,所有电子邮件将具有相同的外观,但仍将是个性化的。本示例代码使用ADO的Connection对象连接到MS Access数据库。然后,ADO的Recordset对象被“电子邮件”表中的值填充。该表的每个记录然后用于生成单个电子邮件。
该代码假定数据库位于C:\ Docs \ simple_merge.mdb文件中,并且“电子邮件”表如下所示:

Visual Basic:
' Mailer object
Dim objSMTP
' ADO Connection object
Dim objConn
' ADO Recordset object
Dim rsEmails
' Merge patterns (Body and "To:", all other fields remain
' unchanged for all e-mails in the mailing list)
Dim strBodyPattern, strToPattern
' Define body pattern
strBodyPattern = "Hello %%FIRST_NAME%%, " & vbCrLf & _
"You are welcome to visit our site at:" & vbCrLf & _
"//www.site.com" & vbCrLf & vbCrLf & _
"Sincerely, Site Team"
' Define "To:" pattern (will look like
' "John Doe " in e-mail)
strToPattern = "%%FIRST_NAME%% %%LAST_NAME%% <%%EMAIL%%>"
' Create SMTP mailer component
Set objSMTP = CreateObject("MailBee.SMTP")
' Enable logging SMTP session into a file. If any
' errors occur, the log can be used to investigate
' the problem.
objSMTP.EnableLogging = True
objSMTP.LogFilePath = "C:\smtp_log.txt"
objSMTP.ClearLog
' Unlock mailer component
objSMTP.LicenseKey = "put your license key here"
' Specify SMTP server name
objSMTP.ServerName = "smtp.site.com"
' Comment next 3 lines if your SMTP server does not
' require SMTP authentication
objSMTP.AuthMethod = 2
objSMTP.UserName = "your mail account name"
objSMTP.Password = "your mail account password"
' Connect to the server. We use single connection
' for sending all e-mails in the database.
If objSMTP.Connect Then
' Plain-text e-mail. Change to 1 to send HTML e-mail
objSMTP.BodyFormat = 0
' Specify "From:" and "Subject:". They remain unchanged
' for all the e-mails.
objSMTP.Message.FromAddr = "Site Team "
objSMTP.Message.Subject = "Invitation"
' Create ADO Connection object
Set objConn = CreateObject("ADODB.Connection")
' Connect to Access database
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\Docs\simple_merge.mdb;"
' Create ADO Recordset object
Set rsEmails = CreateObject("ADODB.Recordset")
' Open "emails" table. This table is
' actual data source for the merge
rsEmails.Open "emails", objConn
' Loop through the table
While Not rsEmails.EOF
' Merge body pattern and actual data
' from the database
objSMTP.Message.BodyText = strBodyPattern
objSMTP.Message.BodyText = Replace(objSMTP.Message.BodyText, "%%FIRST_NAME%%", rsEmails("first_name"))
' Merge "To:" pattern and actual data
' from the database
objSMTP.Message.ToAddr = strToPattern
objSMTP.Message.ToAddr = Replace(objSMTP.Message.ToAddr, "%%FIRST_NAME%%", rsEmails("first_name"))
objSMTP.Message.ToAddr = Replace(objSMTP.Message.ToAddr, "%%LAST_NAME%%", rsEmails("last_name"))
objSMTP.Message.ToAddr = Replace(objSMTP.Message.ToAddr, "%%EMAIL%%", rsEmails("email"))
' Try to send e-mail
If Not objSMTP.Send Then
' Notify user on sending error
MsgBox "Error #" & objSMTP.ErrCode & ", " & objSMTP.ErrDesc
End If
' Proceed with the next record in the table
rsEmails.MoveNext
Wend
' Close the table and the whole database
rsEmails.Close
objConn.Close
' Free database-related objects
Set rsEmails = Nothing
Set objConn = Nothing
' Disconnect from SMTP server
objSMTP.Disconnect
Else
' Notify user on connection error
MsgBox "Error #" & objSMTP.ErrCode & ", " & objSMTP.ErrDesc
End If
ASP:
<% ' Mailer object Dim objSMTP ' ADO Connection object Dim objConn ' ADO Recordset object Dim rsEmails ' Merge patterns (Body and "To:", all other fields remain ' unchanged for all e-mails in the mailing list) Dim strBodyPattern, strToPattern ' Define body pattern strBodyPattern = "Hello %%FIRST_NAME%%, " & vbCrLf & _ "You are welcome to visit our site at:" & vbCrLf & _ "//www.site.com" & vbCrLf & vbCrLf & _ "Sincerely, Site Team" ' Define "To:" pattern (will look like ' "John Doe接下来会还有邮件合并和批量电子邮件-高级的相关教程,多多关注,不要错过哦!您也可以在评论留下你的经验和建议。除了本教程,想要了解更多电子邮件相关产品信息的可以点击此处查看。有更多教程资源等着你!" in e-mail) strToPattern = "%%FIRST_NAME%% %%LAST_NAME%% <%%EMAIL%%>" ' Create SMTP mailer component Set objSMTP = Server.CreateObject("MailBee.SMTP") ' Enable logging SMTP session into a file. If any ' errors occur, the log can be used to investigate ' the problem. objSMTP.EnableLogging = True objSMTP.LogFilePath = "C:\smtp_log.txt" objSMTP.ClearLog ' Unlock mailer component objSMTP.LicenseKey = "put your license key here" ' Specify SMTP server name objSMTP.ServerName = "smtp.site.com" ' Comment next 3 lines if your SMTP server does not ' require SMTP authentication objSMTP.AuthMethod = 2 objSMTP.UserName = "your mail account name" objSMTP.Password = "your mail account password" ' Connect to the server. We use single connection ' for sending all e-mails in the database. If objSMTP.Connect Then ' Plain-text e-mail. Change to 1 to send HTML e-mail objSMTP.BodyFormat = 0 ' Specify "From:" and "Subject:". They remain unchanged ' for all the e-mails. objSMTP.Message.FromAddr = "Site Team " objSMTP.Message.Subject = "Invitation" ' Create ADO Connection object Set objConn = Server.CreateObject("ADODB.Connection") ' Connect to Access database objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _ "Data Source=C:\Docs\simple_merge.mdb;" ' Create ADO Recordset object Set rsEmails = Server.CreateObject("ADODB.Recordset") ' Open "emails" table. This table is ' actual data source for the merge rsEmails.Open "emails", objConn ' Loop through the table While Not rsEmails.EOF ' Merge body pattern and actual data ' from the database objSMTP.Message.BodyText = strBodyPattern objSMTP.Message.BodyText = Replace(objSMTP.Message.BodyText, "%%FIRST_NAME%%", rsEmails("first_name")) ' Merge "To:" pattern and actual data ' from the database objSMTP.Message.ToAddr = strToPattern objSMTP.Message.ToAddr = Replace(objSMTP.Message.ToAddr, "%%FIRST_NAME%%", rsEmails("first_name")) objSMTP.Message.ToAddr = Replace(objSMTP.Message.ToAddr, "%%LAST_NAME%%", rsEmails("last_name")) objSMTP.Message.ToAddr = Replace(objSMTP.Message.ToAddr, "%%EMAIL%%", rsEmails("email")) ' Try to send e-mail If Not objSMTP.Send Then ' Notify user on sending error Response.Write "Error #" & objSMTP.ErrCode & ", " & objSMTP.ErrDesc & " " End If ' Proceed with the next record in the table rsEmails.MoveNext Wend ' Close the table and the whole database rsEmails.Close objConn.Close ' Free database-related objects Set rsEmails = Nothing Set objConn = Nothing ' Disconnect from SMTP server objSMTP.Disconnect Else ' Notify user on connection error Response.Write "Error #" & objSMTP.ErrCode & ", " & objSMTP.ErrDesc & " " End If %>
==========================================
如果想要购买正版授权MailBee.NET Objects的朋友,可以联系
关注慧聚IT微信公众号 ☟☟☟,了解产品的最新动态及最新资讯。
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@ke049m.cn
文章转载自:



本文将为大家介绍一些MyEclipse开发过程中能用到的EJB开发工具,欢迎下载最新版体验!
本文主要介绍如何在MVVM应用程序中使用虚拟源,欢迎下载最新版组件体验!
Parasoft C/C++test是一款功能强大的代码测试与分析工具,专为提升代码质量、确保软件安全与可靠性而设计。要在 Ubuntu 桌面环境中使用这一强大的工具,第一步就是完成其安装与许可证配置。
注意: Cogent DataHub 软件 v11 包含一些新功能,您的目标操作系统可能不支持这些功能。
相关产品
帮助创建并将邮件发送到SMTP服务器并从POP3服务器接收、解析及删除电子邮件,也能在IMAP4服务器上管理电子邮件以及文件夹
最新文章 MORE
半岛外围网上直营相关的文章 MORE
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@ke049m.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
半岛外围网上直营