Last active
September 30, 2022 12:37
-
-
Save kwokhou/6307219 to your computer and use it in GitHub Desktop.
Sending email with outlook.com via C# SmtpClient
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
private void button1_Click(object sender, EventArgs e) | |
{ | |
var mail = new MailMessage(); | |
mail.From = new MailAddress(textBoxFrom.Text); | |
mail.To.Add(textBoxTo.Text); | |
mail.Subject = textBoxSubject.Text; | |
mail.IsBodyHtml = true; | |
string htmlBody; | |
htmlBody = textBoxMessage.Text; | |
mail.Body = htmlBody; | |
var SmtpServer = new SmtpClient("smtp.live.com"); // or "smtp.gmail.com" | |
SmtpServer.Port = 587; | |
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network; | |
SmtpServer.UseDefaultCredentials = false; | |
SmtpServer.Credentials = new System.Net.NetworkCredential(textBoxFrom.Text, textBoxFromLogin.Text); | |
SmtpServer.EnableSsl = true; | |
SmtpServer.SendAsync(mail, "Random123"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
doesnt work