About TemplateMailer :: Try / Purchase :: Support :: Company Information :: Feedback

Processing email manually with TemplateMailer

For more advanced .NET development it may be desired to manually process email and using the TemplateMailer system can greatly simplify this process. This method works ideally with ecommerce systems, broadcast email components and other email specific scenarios.

The TemplateMailer system exposes a number of its functions for public use. Here is a typical step-by-step email integration.

Here's a simple method to execute the full TemplateMailer .

To begin, add a reference in your code to the TemplateMailer. This will expose the various TemplateMailer properties and functions.

[VB.NET]

Dim TemplateMailer As New TectonicConcepts.TemplateMailer.SendTemplateEmail

Next execute the TemplateMailer process to send the message.

TemplateMailer.SendTemplateMail("Response from the TemplateMailer Website", "MailTemplates/ContactUsForm.txt", "MailTemplates/ContactUsForm.html", "customersvc@templatemailer.com", "sales@templatemailer.com", "", True, True, True, False, Me.Controls)

This method exposes the following parameters to be set in one line.

SendTemplateMail(string EmailSubject, string TextTemplate, string HTMLTemplate, string SenderEmailAddress, string RecipientEmailAddress, string CCEmailAddress, bool useDotNetControl, bool SendIPInformation, bool ByPassRecipientList, bool Debug, System.Web.UI.ControlCollection Collection)

Here's a more advanced situation that exposes most of the TemplateMailer properties.

To begin, add a reference in your code to the TemplateMailer. This will expose the various TemplateMailer properties and functions.

[C#]
TectonicConcepts.TemplateMailer.SendTemplateEmail TemplateMailer = new TectonicConcepts.TemplateMailer.SendTemplateEmail();

Now to start the process, the config.xml file must be loaded.

TemplateMailer.ConfigFile = "[location of your config file]"; // This will load the default settings and license.

You can also define any of the properties as listed in the Server Control Properties as defined in the Support section.

If you want to pass a list of other variables to be parsed by the templates besides form fields it can be done now. The name/value pairs are loaded in the form of a hashtable.

TemplateMailer.LoadMyVars(hashtable);

next load the TemplateMailer system.

TemplateMailer.LoadConfig();

next pass the current page control collection.

TemplateMailer.passCollection(this.Controls);

By default all of the TEXT, HTML, Confirmation and AutoResponse templates are now loaded. You can easily override their values and manually assign them. This is only necessary if you want to add additional information to the templates which does not already exist. To parse the text email template call the following. The variable txtTemplate should be the filepath to your TEXT email template.

string myTextEmail;
myTextEmail= TemplateMailer.readTemplate(txtTemplate):

This step can be repeated for the HTML email, Confirmation message and AutoResponse message.

string myHTMLEmail;
myHTMLEmail= TemplateMailer.readTemplate(htmlTemplate):

Now to start the message.

TectonicConcepts.TemplateMailer.SmtpMessage _SmtpMessage = new TectonicConcepts.TemplateMailer.SmtpMessage();
TectonicConcepts.TemplateMailer.SmtpMailer _SmtpMailer = new TectonicConcepts.TemplateMailer.SmtpMailer();
_SmtpMessage.MailFrom = [email address to send from];
_SmtpMessage.MailTo.Add([one email address to send to, repeat for as many recipients, address will be validated);
_SmtpMessage.MailCc.Add([one email address to send to, repeat for as many recipients, address will be validated);
_SmtpMessage.MailBcc.Add([one email address to send to, repeat for as many recipients, address will be validated);
_SmtpMessage.MailBodyText= myTextEmail;
_SmtpMessage.MailBodyHTML= myHTMLEmail;
_SmtpMessage.MailSubject = TemplateMailer.Subject;
_SmtpMailer.SmtpServer = TemplateMailer.MailServer;
_SmtpMailer.Username = [Your SMTP Username];
_SmtpMailer.Password = [Your SMTP Password];
_SmtpMailer.SmtpPort = Convert.ToInt16(TemplateMailer.MailPort);
_SmtpMailer.SendAsHTML = TemplateMailer.SendHTML;
_SmtpMailer.SendMail(_SmtpMessage);
TemplateMailer.Redirect(); // Redirects the user to a URL if the redirectURL variable is defined.

As you can see, whether you choose to use all of the TemplateMailer functionality or just want to send an email, the TemplateMailer system can help. Please note, when using the advanced capabilities of the TemplateMailer, it still follows the same spamming and licensing guidelines as stated previously within the documentation.



Copyright 2001 - 2017
Tectonic Concepts, LLC, All Rights Reserved