提供3000多款全球软件/控件产品
针对软件研发的各个阶段提供专业培训与技术咨询
根据客户需求提供定制化的软件开发服务
全球知名设计软件,显著提升设计质量
打造以经营为中心,实现生产过程透明化管理
帮助企业合理产能分配,提高资源利用率
快速打造数字化生产线,实现全流程追溯
生产过程精准追溯,满足企业合规要求
以六西格玛为理论基础,实现产品质量全数字化管理
通过大屏电子看板,实现车间透明化管理
对设备进行全生命周期管理,提高设备综合利用率
实现设备数据的实时采集与监控
利用数字化技术提升油气勘探的效率和成功率
钻井计划优化、实时监控和风险评估
提供业务洞察与决策支持实现数据驱动决策
原创|使用教程|编辑:龚雪|2015-11-10 16:31:03.000|阅读 398 次
概述:本文将介绍如何用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邮件

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




在现代软件开发过程中,代码质量与可靠性是确保项目成功的关键要素。作为一款领先的自动化测试工具,Parasoft C/C++test 提供了一套完整的解决方案,帮助开发团队执行静态代码分析、单元测试、运行时错误检测等多项质量保障活动。通过深度插桩与动态监控能力,C/C++test 能够精准捕捉代码中的内存泄露、资源未释放等运行时缺陷。
本教程主要介绍如何使用DevExpress WinForms数据网格控件创建和自定义在分组行和分组页脚中显示的摘要,欢迎下载最新版体验!
在嵌入式系统中,函数往往依赖于外部设备状态或其他模块的返回结果,这使得测试的复杂性显著增加。在实际测试过程中,经常会遇到一个函数多次调用另一个依赖函数,并且需要根据不同的调用顺序返回不同结果的情况。Parasoft C/C++test 作为一款专业的自动化测试工具能够通过桩函数实现多次调用返回不同值,从而完成对复杂逻辑的充分测试。
在现代软件开发过程中,自动化单元测试是确保代码质量与可靠性的关键环节。尤其对于特定框架(如MFC)的代码,测试复杂度显著增加,常因依赖外部资源或交互操作而难以在静默环境中顺利执行。Parasoft C/C++test作为专业的软件测试工具,致力于帮助开发团队高效实施自动化测试,通过其强大的桩函数功能,能够有效模拟依赖组件的行为,从而实现对复杂逻辑的隔离测试。
相关产品
Neodynamic公司的Barcode Professional for ASP.NET是一款.NET服务器控件,通过它,您可以在您的ASP.NET Web应用程序中添加条形码图像。
最新文章 MORE
相关文章 MORE
服务电话
重庆/ 023-68661681
华东/ 13452821722
华南/ 18100878085
华北/ 17347785263
客户支持
技术支持咨询服务
服务热线:400-700-1020
邮箱:sales@evget.com
关注我们
地址 : 重庆市九龙坡区火炬大道69号6幢
慧都科技 版权所有 Copyright 2003-
2025 渝ICP备12000582号-13 
渝公网安备
50010702500608号
首页