Skip to content

Instantly share code, notes, and snippets.

@danielplawgo
Created April 24, 2018 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielplawgo/5d70b7b654bc3eb8616a9dcf625088ea to your computer and use it in GitHub Desktop.
Save danielplawgo/5d70b7b654bc3eb8616a9dcf625088ea to your computer and use it in GitHub Desktop.
Send Emails with Hangfire and Postal
@model HangfireAndPostal.Models.RegisterUserEmail
To: @Model.Email
Subject: New Account
<h1>Hi @Model.FirstName!</h1>
<p>Thank you for creating an account.</p>
public class RegisterUserEmail : Email
{
public string FirstName { get; set; }
public string Email { get; set; }
}
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
GlobalConfiguration.Configuration
.UseSqlServerStorage("DefaultConnection");
app.UseHangfireDashboard();
app.UseHangfireServer();
}
}
public void SendEmail(User user)
{
var email = new RegisterUserEmail()
{
FirstName = user.FirstName,
Email = user.Email
};
var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));
var engines = new ViewEngineCollection();
engines.Add(new FileSystemRazorViewEngine(viewsPath));
var emailService = new EmailService(engines);
emailService.Send(email);
}
[HttpPost]
public ActionResult Create(User user)
{
if (ModelState.IsValid == false)
{
return View(user);
}
BackgroundJob.Enqueue(() => SendEmail(user));
return Content("Added");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment