EmailSender.cs 978 B

12345678910111213141516171819202122232425262728293031
  1. using MimeKit;
  2. using MailKit.Net.Smtp;
  3. using System.Threading.Tasks;
  4. namespace HyperCube
  5. {
  6. public class EmailSender
  7. {
  8. public async Task SendEmailAsync(string email, string subject, string message)
  9. {
  10. var emailMessage = new MimeMessage();
  11. emailMessage.From.Add(new MailboxAddress("qhash.ru", "registration@qhash.ru"));
  12. emailMessage.To.Add(new MailboxAddress("", email));
  13. emailMessage.Subject = subject;
  14. emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html)
  15. {
  16. Text = message
  17. };
  18. using (var client = new SmtpClient())
  19. {
  20. await client.ConnectAsync("mail.qhash.ru", 465, true);
  21. await client.AuthenticateAsync("registration@qhash.ru", "4sI:KN5Ssh_tU");
  22. await client.SendAsync(emailMessage);
  23. await client.DisconnectAsync(true);
  24. }
  25. }
  26. }
  27. }