Skip to content

Instantly share code, notes, and snippets.

@salesHgabriel
Last active October 11, 2024 13:32
Show Gist options
  • Save salesHgabriel/5ace25bf40521ba81d5ffd748fa9f932 to your computer and use it in GitHub Desktop.
Save salesHgabriel/5ace25bf40521ba81d5ffd748fa9f932 to your computer and use it in GitHub Desktop.
Send Mail with Outlook and C#
using System.Net.Mail;
Console.WriteLine("--------- PLAYGROUND ----------");
SendEmail();
static void SendEmail()
{
string to = "[email protected]";
string from = "[email protected]";
string subject = "Using the new SMTP client.";
string body = @"Using this new feature, you can send an email message from an application very easily.";
MailMessage message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient("smtp.office365.com");
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(
"[email protected]",
"you_password");
client.Port = 587;
client.EnableSsl = true;
try
{
client.Send(message);
Console.WriteLine("Mail sended :>");
}
catch (Exception e)
{
Console.WriteLine("Error in Send email: {0}", e.Message);
throw;
}
message.Dispose();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment