Last active
January 3, 2023 13:53
-
-
Save wattanar/e8cee974456fd80d9ce649d951f36608 to your computer and use it in GitHub Desktop.
C# Send Email With MailKit
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
| namespace ConsoleApp | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var message = new MimeMessage(); | |
| var bodyBuilder = new BodyBuilder(); | |
| // from | |
| message.From.Add(new MailboxAddress("from_name", "[email protected]")); | |
| // to | |
| message.To.Add(new MailboxAddress("to_name", "[email protected]")); | |
| // reply to | |
| message.ReplyTo.Add(new MailboxAddress("reply_name", "[email protected]")); | |
| message.Subject = "subject"; | |
| bodyBuilder.HtmlBody = "html body"; | |
| message.Body = bodyBuilder.ToMessageBody(); | |
| var client = new SmtpClient(); | |
| client.ServerCertificateValidationCallback = (s, c, h, e) => true; | |
| client.Connect("MAIL_SERVER", 465, SecureSocketOptions.SslOnConnect); | |
| client.Authenticate("USERNAME", "PASSWORD"); | |
| client.Send(message); | |
| client.Disconnect(true); | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update 2019 !! :)