Advertisement
MadCortez

Untitled

Jun 27th, 2023
1,054
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using MimeKit;
  2. using MailKit.Net.Smtp;
  3.  
  4. namespace MyCloud.Helpers
  5. {
  6.     public static class MailHelper
  7.     {
  8.         public static async Task SendEmail(string email, string subject, string message)
  9.         {
  10.             using var emailMessage = new MimeMessage();
  11.  
  12.             emailMessage.From.Add(new MailboxAddress("Администрация сайта", ""));
  13.             emailMessage.To.Add(new MailboxAddress("", email));
  14.             emailMessage.Subject = subject;
  15.             emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Plain)
  16.             {
  17.                 Text = message
  18.             };
  19.  
  20.             using (var client = new SmtpClient())
  21.             {
  22.                 await client.ConnectAsync("smtp.mail.ru", 465, true);
  23.                 await client.AuthenticateAsync("", "");
  24.                 await client.SendAsync(emailMessage);
  25.  
  26.                 await client.DisconnectAsync(true);
  27.             }
  28.         }
  29.     }
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement