-
Notifications
You must be signed in to change notification settings - Fork 1
Getting started
wduffy edited this page Jun 10, 2011
·
3 revisions
There are two key elements to sending a RazorMail.
- A RazorMailMessage which is responsible for rendering the final email body
- An IRazorMailSender which asks a RazorMailMessage to render its templates and emails the result via SMTP
The default IRazorMailSender is RazorMailSender, which requires a minimum of two arguments to construct.
- sender: The MailAddress to be used as the sender for any messages it handles. This is NOT the from address, however, if a from address is not specified it will be used for this purpose.
- baseUri: The uri that represents the location that will handle all relative links on emails. Any rooted or relative urls are resolved to base urls using this before sending.
var mailsender = new RazorMailSender(new MailAddress("business@domain.com", "Business Name"), HttpContext.Request.Url);
var message = new RazorMailMessage("Test Message");
message.From = new MailAddress("from@domain.com", "From Name");
message.To.Add("recipient@domain.com", "Recipient Name");
message.Templates.Add("This is a RazorMail test by @Model.Name");
message.Set.Name = "William Duffy";
mailsender.Send(message);
var smtp = new SmtpClient("smtp.domain.com") { Credentials = new NetworkCredential("username", "password") };
var mailsender = new RazorMailSender(new MailAddress("business@domain.com", "Business Name"), HttpContext.Request.Url, null, smtp);
var message = new RazorMailMessage("Test Message");
message.From = new MailAddress("from@domain.com", "From Name");
message.To.Add("recipient@domain.com", "Recipient Name");
message.Templates.Add("This is a RazorMail test by @Model.Name");
message.Set.Name = "William Duffy";
mailsender.Send(message);