Ok, I've read tons of posts about this topic, still it doesn't work. I'm trying to send email via the smpt server of office365. Of course I checked the credentials logging in from the browser.
smtpClient.Host = "smtp.office365.com";
smtpClient.Port = 587;
smtpClient.Credentials = new System.Net.NetworkCredential(username, password, "MicrosoftOffice365Domain.com");
smtpClient.UseDefaultCredentials = false;
smtpClient.EnableSsl = true;
smtpClient.TargetName = "STARTTLS/smtp.office365.com";
I get an exception and the emails are not sent:
Exception thrown: 'System.Net.Mail.SmtpException' in System.dll Failure sending mail. System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond xx.xxx.xx.x:587 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) --- End of inner exception stack trace --- at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message)
Is there something other I need to add in the configuration?
UPDATE
After rebooting something has changed. Now it actually connects with the server but this time I get this exception:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM
Why does it say the email is "anonymous"?
I set the FROM
field to the same email address used for the authentication.