Skip to content

Instantly share code, notes, and snippets.

@kwokhou
Last active September 30, 2022 12:37
Show Gist options
  • Save kwokhou/6307219 to your computer and use it in GitHub Desktop.
Save kwokhou/6307219 to your computer and use it in GitHub Desktop.
Sending email with outlook.com via C# SmtpClient
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");
}
@PatrickDinoCallaghan
Copy link

doesnt work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment