Last active
October 11, 2024 13:32
-
-
Save salesHgabriel/5ace25bf40521ba81d5ffd748fa9f932 to your computer and use it in GitHub Desktop.
Send Mail with Outlook and C#
This file contains 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
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