cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Office 365 sending email from C#

I am trying to send email through my c# code but It is giving error 

An attempt was made to access a socket in a way forbidden by its access permissions 40.97.188.2:587

my code for sending email is 

 

SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("email@mysite.ca", "password");
client.Port = 587;
client.Host = "smtp.office365.com";
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.EnableSsl = true;

client.Send(msg);

 

 I contacted godaddy support but they said everything is good at their side. 

1 REPLY 1
Employee

Hello @hzuberi ,

 

Welcome to the Community!  I wanted to reach out to let you know I've seen your post, but sending emails with C# is not something I'm familiar with.  Just curious, what benefit or advantage do you have in sending this way versus through Webmail?  

Hopefully a coding guru in our community will see your post, but if you need server settings, this article  should ensure you have the correct ones.  Have a great weekend! 

Sales and Support available 24/7 via phone or chat