Reputation: 572
I tried to write c# code to send emails through my work mail account. I already connected the email account to my android smartphone and it's working well. I took the connection data from it and now I'm trying to send email with c# but I can't manage it. I used the same c# code to send email from my gmail account and it work fine, but when I try to use it with my work account I can't. Am I doing something wrong?
My code is:
MailMessage mail = new MailMessage();
mail.To.Add(new MailAddress("myPersonalEmailAddress"));
mail.From = new MailAddress("myWorkEmailAddress");
mail.Subject = "Test subject";
mail.Body = "Test body";
/*
* The server name, port and domain are similar to smartphone account
* It also uses SSL so I enabled it
*/
SmtpClient client = new SmtpClient("serverName", 443);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("username", "password", "domain");
client.EnableSsl = true;
client.Timeout = 20000;
try
{
client.Send(mail);
}
catch (Exception e)
{
}
Upvotes: 1
Views: 373
Reputation: 360
you should make allow access for this in your gmail account then it will work fine
Upvotes: 1