Место общения программистов C#
Anonymous
Отправка почты с помощью SMTP-сервера Office365
Сообщение
Anonymous » 24 янв 2025, 13:39
Я пытаюсь отправить почту с помощью библиотеки Aegis Implicit Mail, и мой SMTP-сервер — Office 365.
Адрес SMTP-сервера: smtp.office365.com
Порт SMTP: 587
Но я получаю следующую ошибку:
[*]Порт SMTP: 587
Но я получаю эту ошибку:
Это мой код:
Код: Выделить всё
public void Send(string body, string subject, List attch, string smtpServer, int smtpPort, string smtpFrom, string smtpTo)
{
var myMsg = new MimeMailMessage();
myMsg.From = new MimeMailAddress(smtpFrom);
string[] toAdds = smtpTo.Split(';');
foreach(string toAdd in toAdds)
{
myMsg.To.Add(toAdd);
}
if (attch != null)
{
foreach (MimeAttachment attch2 in attch)
{
myMsg.Attachments.Add(attch2);
}
}
var mailer = new MimeMailer(smtpServer, smtpPort);
mailer.User = "login";
mailer.Password = "password";
mailer.EnableImplicitSsl = true;
mailer.SslType = SslMode.Tls;
mailer.AuthenticationMode = AuthenticationType.PlainText;
mailer.SendCompleted += compEvent;
mailer.SendMailAsync(myMsg);
}
private void compEvent(object sender, AsyncCompletedEventArgs e)
{
if (e.UserState != null)
Console.Out.WriteLine(e.UserState.ToString());
Console.Out.WriteLine("is it canceled? " + e.Cancelled);
if (e.Error != null)
Console.Out.WriteLine("Error : " + e.Error.Message);
}
Пожалуйста - что я делаю не так?
Подробнее здесь:
https://stackoverflow.com/questions/793 ... -office365
1737715160
Anonymous
Я пытаюсь отправить почту с помощью библиотеки Aegis Implicit Mail, и мой SMTP-сервер — Office 365. [list] [*]Адрес SMTP-сервера: smtp.office365.com [*]Порт SMTP: 587 [/list] Но я получаю следующую ошибку: [*]Порт SMTP: 587 Но я получаю эту ошибку: [img]https://i.sstatic.net/CbXee4Ur.png[/img] Это мой код: [code]public void Send(string body, string subject, List attch, string smtpServer, int smtpPort, string smtpFrom, string smtpTo) { var myMsg = new MimeMailMessage(); myMsg.From = new MimeMailAddress(smtpFrom); string[] toAdds = smtpTo.Split(';'); foreach(string toAdd in toAdds) { myMsg.To.Add(toAdd); } if (attch != null) { foreach (MimeAttachment attch2 in attch) { myMsg.Attachments.Add(attch2); } } var mailer = new MimeMailer(smtpServer, smtpPort); mailer.User = "login"; mailer.Password = "password"; mailer.EnableImplicitSsl = true; mailer.SslType = SslMode.Tls; mailer.AuthenticationMode = AuthenticationType.PlainText; mailer.SendCompleted += compEvent; mailer.SendMailAsync(myMsg); } private void compEvent(object sender, AsyncCompletedEventArgs e) { if (e.UserState != null) Console.Out.WriteLine(e.UserState.ToString()); Console.Out.WriteLine("is it canceled? " + e.Cancelled); if (e.Error != null) Console.Out.WriteLine("Error : " + e.Error.Message); } [/code] Пожалуйста - что я делаю не так? Подробнее здесь: [url]https://stackoverflow.com/questions/79383975/send-mail-with-smtp-server-office365[/url]