Guest User

Untitled

a guest
Jun 14th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. using Microsoft.AspNetCore.Identity.UI.Services;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Net;
  5. using System.Net.Mail;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace MailSenderApp.Services {
  10. public class EmailSender : IEmailSender {
  11.  
  12. // Our private configuration variables
  13. private string host;
  14. private int port;
  15. private bool enableSSL;
  16. private string userName;
  17. private string password;
  18.  
  19. // Get our parameterized configuration
  20. public EmailSender(string host, int port, bool enableSSL, string userName, string password) {
  21. this.host = host;
  22. this.port = port;
  23. this.enableSSL = enableSSL;
  24. this.userName = userName;
  25. this.password = password;
  26. }
  27.  
  28. // Use our configuration to send the email by using SmtpClient
  29. public Task SendEmailAsync(string email, string subject, string htmlMessage) {
  30. var client = new SmtpClient(host, port) {
  31. Credentials = new NetworkCredential(userName, password),
  32. EnableSsl = enableSSL
  33. };
  34. return client.SendMailAsync(
  35. new MailMessage(userName, email, subject, htmlMessage) { IsBodyHtml = true }
  36. );
  37. }
  38. }
  39. }
Add Comment
Please, Sign In to add comment