Neodynamic Barcode Professional 3.0 (or greater) for Windows Forms (WinControl)
Microsoft .NET Framework 2.0 (or greater)
Microsoft Visual Studio 2005
Microsoft Visual Studio 2005 Express Editions (VB, C#, J#, and C++)
In the following Step-By-Step Guide we're going to create a simple Windows Form which lets you to generate and send HTML emails featuring barcode images (some useful scenarios may involve any kind of barcode tickets, newsletters, invitations, and so on) created by Barcode Professional for Windows Forms and the System.Net.Mail classes.
Private Function GetBarcodeImage() As System.IO.MemoryStream
'Create an instance of BarcodeProfessional class
Dim bcp As New Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional()
'Set barcode settings...
'Code 128 symbology
bcp.Symbology = Neodynamic.WinControls.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 Function
private System.IO.MemoryStream GetBarcodeImage()
{
//Create an instance of BarcodeProfessional class
Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional();
//Set barcode settings...
//Code 128 symbology
bcp.Symbology = Neodynamic.WinControls.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));
}
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""><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></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 Sub
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\"><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></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);
}
We provide best-in-class customer service and support directly from members of our dev team! If we are available when you contact us, you will get a response in few minutes; otherwise the maximum turnaround is 24hs in most cases.