|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionThe purpose of this article is to help you in sending dynamically generated EMails. The EMail body can be set using a text file or an URL, and can contain a special dynamic field, a How to set the EMail body dynamically?Note that you can set two kind of EMail body: Text and HTML. The EMail body can be set by different ways. The easiest way is to set the body directly using a
What is a dynamic field?A dynamic field is a special tag that will be replaced with an appropriate value just before sending the EMail. So, you can create your EMail template with your favorite HTML editor and insert a special tag, named
BackgroundThere's no background needed for using this package but the main problem you can have is with your EMail server. IIS SMTP Virtual server is an Open Relay server and can send your email automatically, but the risk is that the SMTP server of your correspondent will reject the EMail; because your SMTP relay is open or not official (no MX declaration in the DNS zone). So, you can use your own official SMTP account, given by your internet provider. InstallationDownload the ZIP file and extract it on your 'c:\temp' folder. The solution has been made with VS.NET 2003 v7.1.3088, with .NET Framework v1.1.4322 SP1. See alsoYou can refer to my article "BooProd.Core - Context Sensitive URL" on treating of context sensitive URL generation. This package will be useful if you need to replace URLs depending on the execution context. Using the codeSimple useHere is a simple way to create an EMail : BMail vBMail= new BMail();
vBMail.From= "myEMail@xx.com";
vBMail.To= "myFriend@yy.com";
vBMail.Subject= "The subject";
vBMail.setBodyAsText("Hello, this is an EMail");
If your host can't send EMail directly or is not trusted by your SMTP relay server, authenticate yourself to your SMTP server in the same way you did with Outlook. vBMail.SMTPAutenticate= BMail.SMTP_AUTH_BASIC;
vBMail.SMTPServer= "smtp.myprovider.com";
vBMail.SMTPUserName= "myLogin";
vBMail.SMTPPassword= "myPassword";
Then, send the EMail. vBMail.send();
Advanced useThe best way to use this package is setting the EMail body dynamically and then replacing parts of the EMail dynamically. /// The 'true' parameter indicates that the file is an HTML file
vBMail.setBodyFromFile("EMailTemplate.html", true);
/// Replace 3 BMAIL Tag inside the HTML file
vBMail.replaceFrom("name", "John");
vBMail.replaceFrom("number", "1234");
vBMail.replaceFrom("year", DateTime.Now.Year.ToString());
Demo ProjectA demo application is provided: "BooProd.BMail.Tester". Each step is in a different color.
Enjoy! Points of Interest
History
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||