Last active
June 13, 2018 03:56
-
-
Save danielplawgo/331fbd36cca8273e7daa4e5db8b7f09d to your computer and use it in GitHub Desktop.
Postal - wysyłka email w ASP.NET MVC
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 BaseMailer | |
{ | |
protected void Send(Email email) | |
{ | |
var mailerName = GetType().Name.Replace("Mailer", string.Empty); | |
var viewsPath = Path.GetFullPath(string.Format(HostingEnvironment.MapPath(@"~/Views/Emails/{0}"), mailerName)); | |
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
@model PostalExample.ViewModels.Users.RegisterEmail | |
To: @Model.Email | |
Subject: Nowe konto | |
<h1>Witaj @Model.FirstName!</h1> | |
<p>Dziękujemy za założenie konta.</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 RegisterEmail : 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 class UsersMailer : IUserMailer | |
{ | |
public void SendRegisterEmail(User user) | |
{ | |
var email = new RegisterEmail() | |
{ | |
Email = user.Email, | |
FirstName = user.FirstName | |
}; | |
email.Send(); | |
} | |
} | |
public interface IUserMailer | |
{ | |
void SendRegisterEmail(User user); | |
} |
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 UsersMailer : BaseMailer, IUserMailer | |
{ | |
public void SendRegisterEmail(User user) | |
{ | |
var email = new RegisterEmail() | |
{ | |
Email = user.Email, | |
FirstName = user.FirstName | |
}; | |
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
<system.net> | |
<mailSettings> | |
<smtp from="adres email"> | |
<network enableSsl="true" host="smtp.gmail.com" port="587" userName="nazwa użytkownika" password="hasło" /> | |
</smtp> | |
</mailSettings> | |
</system.net> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment