diff --git a/src/Postal/Email.cs b/src/Postal/Email.cs
index d5d433a..e5cbed7 100644
--- a/src/Postal/Email.cs
+++ b/src/Postal/Email.cs
@@ -30,6 +30,23 @@ public Email(string viewName)
ImageEmbedder = new ImageEmbedder();
}
+ ///
+ /// Creates a new Email, that will render the given view using the given model.
+ ///
+ /// The name of the view to render
+ /// The view's model
+ public Email(string viewName, object model)
+ {
+ if (viewName == null) throw new ArgumentNullException("viewName");
+ if (string.IsNullOrWhiteSpace(viewName)) throw new ArgumentException("View name cannot be empty.", "viewName");
+ if (model == null) throw new ArgumentNullException("model");
+
+ Attachments = new List();
+ ViewName = viewName;
+ ViewData = new ViewDataDictionary(model);
+ ImageEmbedder = new ImageEmbedder();
+ }
+
/// Create an Email where the ViewName is derived from the name of the class.
/// Used when defining strongly typed Email classes.
protected Email()
diff --git a/src/Postal/EmailService.cs b/src/Postal/EmailService.cs
index d829a77..ed4c539 100644
--- a/src/Postal/EmailService.cs
+++ b/src/Postal/EmailService.cs
@@ -54,6 +54,20 @@ public void Send(Email email)
}
}
+ ///
+ /// Sends an email using an .
+ ///
+ /// The email to send.
+ /// The name of the view to render.
+ public void Send(string viewName, Email email)
+ {
+ using (var mailMessage = CreateMailMessage(viewName, email))
+ using (var smtp = createSmtpClient())
+ {
+ smtp.Send(mailMessage);
+ }
+ }
+
///
/// Send an email asynchronously, using an .
///
@@ -117,5 +131,21 @@ public MailMessage CreateMailMessage(Email email)
var mailMessage = emailParser.Parse(rawEmailString, email);
return mailMessage;
}
+
+ ///
+ /// Renders the email view and builds a . Does not send the email.
+ ///
+ /// The email to render.
+ /// The name of the view to render.
+ /// A containing the rendered email.
+ public MailMessage CreateMailMessage(string viewName, Email email)
+ {
+ var rawEmailString = emailViewRenderer.Render(email, viewName);
+ var mailMessage = emailParser.Parse(rawEmailString, email);
+ return mailMessage;
+ }
+
+
+
}
}
\ No newline at end of file