lundi 2 février 2015

Sending email in C#


Vote count:

0




I am working on a page where I have to send an email in C#. I wish to send an email from an outlook address to a gmail address.


I followed the codes on http://ift.tt/1xzPoX1 and came upon this two exceptions


A first chance exception of type 'System.Net.Mail.SmtpException' occurred in System.dll. A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll


Here are the codes I implemented. I can't seem to figure what went wrong.



//Send email notification - removed actual email for this question

SmtpClient client = new SmtpClient("smtp-mail.outlook.com", 587);
client.EnableSsl = true;

MailAddress from = new MailAddress("myemail@outlook.com", "My name is here");
MailAddress to = new MailAddress("anotherpersonsemail@gmail.com", "Subject here");

MailMessage message = new MailMessage(from, to);
message.Body = "Thank you";
message.Subject = "Successful submission";

NetworkCredential myCreds = new NetworkCredential("myemail@outlook.com",
"mypassword", "");

client.Credentials = myCreds;
try
{
client.Send(message);
Console.Write(ex.Message.ToString());

}

catch (Exception ex)
{
Console.Write(ex.Message.ToString());
}


asked 2 mins ago







Sending email in C#

Aucun commentaire:

Enregistrer un commentaire