Как использовать Office 365 Outlook для служб электронной почты с помощью C#C#

Место общения программистов C#
Anonymous
Как использовать Office 365 Outlook для служб электронной почты с помощью C#

Сообщение Anonymous »

Я использую электронную почту Outlook.office365.com, но получаю сообщение об ошибке удаления подключения
System.Net.Mail.SmtpException HResult=0x80131500 Message=Failure sending mail.

Source=EmailTesting

Inner Exception 1: WebException: Unable to connect to the remote server

Inner Exception 2: 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 52.101.145.0:587

мой код ниже:
var sClient = new SmtpClient("domainname-com.mail.protection.outlook.com"); // This is MX code, used with smtp.office365.com and outlook.office365.com.. still same error
var message = new MailMessage();

sClient.Port = 587;
sClient.EnableSsl = true;
sClient.Credentials = new NetworkCredential("from-email", "Password");
sClient.UseDefaultCredentials = false;

message.Body = "Test";
message.From = new MailAddress("from-email");
message.Subject = "Test";
message.To.Add(new MailAddress("Receiver-email"));

sClient.Send(message);


Подробнее здесь: https://stackoverflow.com/questions/791 ... ng-c-sharp

Вернуться в «C#»