Simple and Easy way to store/edit email templates in your .net project is to store them as string email body in a html file.
Step 1: Create a HTML mail message
Step 1(a): You can introduce as many as variable in HTML template by any character scheme (@PARAMETER@ or #PARAMETER# or $$PARAMETER$$).
Replace all names/variables with things like #VaraibleName#
The confirmation number is: <b>#confirmNumber#</b>
Step 2: Right click on web project and select Properties from right click menu
Step 4: File will be visible in Resources display pan
Step 5: For Server side C# code
You can refer to HTML email template from Properties.Resources.EmailTemplate.You can use it as a string.
Replace the #PARAMETER# text with the actual values.
private void SendConfirmationEmail(string email, string confirmNumber)
{
var emailBody = Properties.Resources.EmailTemplate.Replace("#confirmNumber#", confirmNumber);
MailMessage message =
new MailMessage
{
From =
new MailAddress("Sender Email Address"),
Subject = "Email Subject Content",
Body = string.Format(emailBody),
IsBodyHtml = true
};
message.To.Add(new MailAddress(email));
SmtpClient client = new SmtpClient("11.111.111.11");
client.Send(message);
}
0 comments:
Post a Comment