Skip to content

Instantly share code, notes, and snippets.

@antdimot
Created March 18, 2019 15:54
Show Gist options
  • Save antdimot/31261e07bc0f1019ec7ccb13c609b342 to your computer and use it in GitHub Desktop.
Save antdimot/31261e07bc0f1019ec7ccb13c609b342 to your computer and use it in GitHub Desktop.
Email from office 365 account
class Program
{
static void Main( string[] args )
{
var to = new MailAddress( <to email here> );
var from = new MailAddress( <from email here> );
var oMail = new MailMessage( from, to )
{
Subject = "test email from office 365 account",
Body = @"Using this new feature, you can send an email message from an application very easily."
};
var oSmtp = new SmtpClient
{
Host = "smtp.office365.com",
Port = 587,
Credentials = new System.Net.NetworkCredential( <email here>, <password here> ),
EnableSsl = true
};
try
{
Console.WriteLine( "start to send email over SSL..." );
oSmtp.Send( oMail );
Console.WriteLine( "email was sent successfully!" );
}
catch( Exception ep )
{
Console.WriteLine( "failed to send email with the following error:" );
Console.WriteLine( ep.Message );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment