Skip to content

Instantly share code, notes, and snippets.

@AymericG
Created April 27, 2012 12:28
Show Gist options
  • Save AymericG/2508833 to your computer and use it in GitHub Desktop.
Save AymericG/2508833 to your computer and use it in GitHub Desktop.
How to use MvcMailer
Mailer.Invitation(emailAddresses.ToArray(), LoggedInUser.Name, inviteMessage).Send();
public abstract class ApplicationController : Controller
{
private UserMailer _mailer = new UserMailer();
public UserMailer Mailer
{
get { return _mailer; }
set { _mailer = value; }
}
}
<h1>@ViewBag.Title</h1>
<p>
<b>@ViewBag.FromUserName</b> sent you this message:
</p>
<p>"@ViewBag.InviteMessage"</p>
<p>
WEEK PLAN is a free weekly planner inspired by the book "Seven Habits of Highly Effective People".
</p>
<p>
<a href="http://weekplan.net/?invited=1">Check WEEK PLAN out</a>.
</p>
= @ViewBag.Title =
@ViewBag.FromUserName sent you this message:
"@ViewBag.InviteMessage"
WEEK PLAN is a free weekly planner inspired by the book "Seven Habits of Highly Effective People".
Check WEEK PLAN out: http://weekplan.net/?invited=1
install-package MvcMailer
Scaffold Mailer UserMailer Invitation,NewPassword,NewComment –WithText –NoInterface
public virtual MailMessage Invitation(string[] tos, string fromUserName, string inviteMessage)
{
var message = new MailMessage
{
Subject = fromUserName + " wants to help you be more effective"
};
foreach (var to in tos)
message.Bcc.Add(to);
// Pass data to the view
ViewBag.Title = "You have received an invitation to use WEEK PLAN";
ViewBag.FromUserName = fromUserName;
ViewBag.InviteMessage = inviteMessage;
// MVCMailer magic
PopulateBody(message, viewName: "Invitation");
return message;
}
<system.net>
<mailSettings>
<smtp from="hello@wiselabs.net" deliveryMethod="SpecifiedPickupDirectory">
<network host="localhost" />
<specifiedPickupDirectory pickupDirectoryLocation="C:\Temp\SMTP Drop"/>
</smtp>
</mailSettings>
</system.net>
<system.net>
<mailSettings xdt:Transform="Replace">
<smtp from="hello@wiselabs.net">
<network enableSsl="true" host="smtp.sendgrid.net" port="587" userName="UserName" password="********" />
</smtp>
</mailSettings>
</system.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment