提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
原创|使用教程|编辑:龚雪|2015-11-10 16:31:03.000|阅读 397 次
概述:本文将介绍如何用Barcode Professional for ASP.NET来生成及发送附有条形码的HTML邮件,附C#和VB代码
#慧都22周年庆大促·界面/图表报表/文档/IDE/IOT/测试等千款热门软控件火热促销中>>
相关链接:
有时候我们需要以邮件形式发送附有条形码的门票、实施通讯、请柬。那么面对这样的情况我们该怎么处理呢?今天我们将介绍如何用Barcode Professional生成及发送有条形码的HTML电子邮件。
参考步骤:

VB
Private Function GetBarcodeImage() As System.IO.MemoryStream
'Create an instance of BarcodeProfessional class
Dim bcp As New Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional()
'Set barcode settings...
'Code 128 symbology
bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128
'Set a fictitious value to encode
bcp.Code = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 20).ToUpper()
'Return barcode stream
Return New System.IO.MemoryStream(bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png))
End FunctionC#
private System.IO.MemoryStream GetBarcodeImage()
{
//Create an instance of BarcodeProfessional class
Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WebControls.BarcodeProfessional.BarcodeProfessional();
//Set barcode settings...
//Code 128 symbology
bcp.Symbology = Neodynamic.WebControls.BarcodeProfessional.Symbology.Code128;
//Set a fictitious value to encode
bcp.Code = Guid.NewGuid().ToString().Replace("-","").Substring(0,20).ToUpper();
//Return barcode stream
return new System.IO.MemoryStream(bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png));
}VB
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Create the mail message
Dim mail As New System.Net.Mail.MailMessage()
'Set the email addresses
mail.From = New System.Net.Mail.MailAddress("me@mycompany.com")
mail.To.Add(Me.TextBox1.Text)
'Set the subject
mail.Subject = "John Doe in Concert - Barcode Ticket"
'Create the Html part.
'To embed the barcode image, we need to use the prefix cid in the img src attribute.
'The cid value will map to the Content-Id of a Linked resource.
'Example: <img src="cid:barcodeticket"> will map to a LinkedResource with a ContentId of barcodeticket
Dim htmlContent1 As String = "<table border="" 1""="" bordercolor="" #000000""="" cellpadding="" 5""="" cellspacing="" 0""="" style="" vertical-align:="" middle;="" width:="" 300px;="" text-align:="" center""=""><tbody><tr><td bgcolor="" #ff6633""="" colspan="" 2""=""><span style="" font-size:="" 10pt;="" color:="" #ffffff;="" font-family:="" arial""=""><b>NEOMIX</b></span></td></tr><tr><td colspan="" 2""=""><span style="" font-family:="" arial="" black""="">ADMIT ONE</span></td></tr><tr><td bgcolor="" #ff6633""="" colspan="" 2""=""><span style="" color:="" #ffffff;="" font-family:="" arial""="">NEO STADIUM</span></td></tr><tr><td colspan="" 2""=""><span style="" font-size:="" 10pt;="" font-family:="" arial""=""><b>GENERAL ADMISSION</b></span></td></tr><tr><td bgcolor="" #ff6633""="" colspan="" 2""=""> </td></tr><tr><td colspan="" 2""=""><span style="" font-size:="" 22pt;="" font-family:="" arial""=""><b>John Doe in Concert</b></span></td></tr><tr><td colspan="" 2""="">"
Dim htmlContent2 As String = "<img src="cid:barcodeticket">"
Dim htmlContent3 As String = "</td></tr><tr><td style="" width:="" 100px""=""><span style="" font-family:="" arial="" black""="">May<br><span style="" font-size:="" 24pt""="">19</span><br>2007</span></td><td style="" width:="" 100px""=""><span style="" font-family:="" arial="" black""="">SATURDAY<br>8:00 PM</span></td></tr><tr><td bgcolor="" #ff6633""="" colspan="" 2""=""><span style="" color:="" #ffffff;="" font-family:="" arial="" black""="">$ 98.00</span></td></tr></tbody></table>"
Dim htmlView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(htmlContent1 + htmlContent2 + htmlContent3, Nothing, "text/html")
'Create the LinkedResource (embedded barcode image)
Dim barcode As New System.Net.Mail.LinkedResource(Me.GetBarcodeImage(), "image/png")
barcode.ContentId = "barcodeticket"
'Add the LinkedResource to the view
htmlView.LinkedResources.Add(barcode)
'Add the view
mail.AlternateViews.Add(htmlView)
'specify the mail server address
Dim smtp As New System.Net.Mail.SmtpClient("127.0.0.1")
'send the message
smtp.Send(mail)
End SubC#
protected void Button1_Click(object sender, EventArgs e)
{
//Create the mail message
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
//Set the email addresses
mail.From = new System.Net.Mail.MailAddress("me@mycompany.com");
mail.To.Add(this.TextBox1.Text);
//Set the subject
mail.Subject = "John Doe in Concert - Barcode Ticket";
//Create the Html part.
//To embed the barcode image, we need to use the prefix 'cid' in the img src attribute.
//The cid value will map to the Content-Id of a Linked resource.
//Example: <img src="cid:barcodeticket"> will map to a LinkedResource with a ContentId of 'barcodeticket'
string htmlContent1 = "<table border="\"1\"" bordercolor="\"#000000\"" cellpadding="\"5\"" cellspacing="\"0\"" style="\"vertical-align:" middle;="" width:="" 300px;="" text-align:="" center\"=""><tbody><tr><td bgcolor="\"#ff6633\"" colspan="\"2\""><span style="\"font-size:" 10pt;="" color:="" #ffffff;="" font-family:="" arial\"=""><b>NEOMIX</b></span></td></tr><tr><td colspan="\"2\""><span style="\"font-family:" arial="" black\"="">ADMIT ONE</span></td></tr><tr><td bgcolor="\"#ff6633\"" colspan="\"2\""><span style="\"color:" #ffffff;="" font-family:="" arial\"="">NEO STADIUM</span></td></tr><tr><td colspan="\"2\""><span style="\"font-size:" 10pt;="" font-family:="" arial\"=""><b>GENERAL ADMISSION</b></span></td></tr><tr><td bgcolor="\"#ff6633\"" colspan="\"2\""> </td></tr><tr><td colspan="\"2\""><span style="\"font-size:" 22pt;="" font-family:="" arial\"=""><b>John Doe in Concert</b></span></td></tr><tr><td colspan="\"2\"">";
string htmlContent2 = "<img src="cid:barcodeticket">";
string htmlContent3 = "</td></tr><tr><td style="\"width:" 100px\"=""><span style="\"font-family:" arial="" black\"="">May<br><span style="\"font-size:" 24pt\"="">19</span><br>2007</span></td><td style="\"width:" 100px\"=""><span style="\"font-family:" arial="" black\"="">SATURDAY<br>8:00 PM</span></td></tr><tr><td bgcolor="\"#ff6633\"" colspan="\"2\""><span style="\"color:" #ffffff;="" font-family:="" arial="" black\"="">$ 98.00</span></td></tr></tbody></table>";
System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(htmlContent1 + htmlContent2 + htmlContent3, null, "text/html");
//Create the LinkedResource (embedded barcode image)
System.Net.Mail.LinkedResource barcode = new System.Net.Mail.LinkedResource(this.GetBarcodeImage(), "image/png");
barcode.ContentId = "barcodeticket";
//Add the LinkedResource to the view
htmlView.LinkedResources.Add(barcode);
//Add the view
mail.AlternateViews.Add(htmlView);
//specify the mail server address
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("127.0.0.1");
//send the message
smtp.Send(mail);
}
当你指定有效地址并点击Send Barcode Ticket后,你将收到上文附有条码的HTML邮件

本文译自
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@hmdbvip.cn




本文主要介绍如何在MVVM应用程序中使用虚拟源,欢迎下载最新版组件体验!
Aspose.Slides for Java使用户能够轻松地操作幻灯片、添加注释和转换文件。其易用性和集成能力提高了工作效率,使开发人员能够专注于更关键的任务。
在嵌入式软件测试领域,对交叉编译代码进行单元测试是一大挑战。Parasoft C/C++test作为专业的C/C++测试工具,能够与劳特巴赫Trace32调试器深度集成。下面会详细介绍如何在C++test中配置Trace32调试器,实现对PowerPC架构程序的单元测试,涵盖环境设置、项目导入到测试执行的全过程。
本文将为大家介绍如何使用DevExpress WinForms数据网格控件实现摘要文本的格式化,欢迎下载最新版组件体验!
相关产品
Neodynamic公司的Barcode Professional for ASP.NET是一款.NET服务器控件,通过它,您可以在您的ASP.NET Web应用程序中添加条形码图像。
最新文章 MORE
永利最大(官方)网站相关的文章 MORE
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@hmdbvip.cn
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
永利最大(官方)网站