Created
April 24, 2018 08:49
-
-
Save danielplawgo/5d70b7b654bc3eb8616a9dcf625088ea to your computer and use it in GitHub Desktop.
Send Emails with Hangfire and Postal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model HangfireAndPostal.Models.RegisterUserEmail | |
To: @Model.Email | |
Subject: New Account | |
<h1>Hi @Model.FirstName!</h1> | |
<p>Thank you for creating an account.</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RegisterUserEmail : Email | |
{ | |
public string FirstName { get; set; } | |
public string Email { get; set; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class Startup | |
{ | |
public void Configuration(IAppBuilder app) | |
{ | |
GlobalConfiguration.Configuration | |
.UseSqlServerStorage("DefaultConnection"); | |
app.UseHangfireDashboard(); | |
app.UseHangfireServer(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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