Yandex smtp settings with ssl

2019-06-01 07:57发布

问题:

I can send emails via enableSsl="false" and 25 port. But it is not enought in case with own domain.

What is wrong or missing in this settings?

<system.net>
    <mailSettings>
      <smtp  deliveryMethod="Network" from="Name">
        <network  host="smtp.yandex.ru" port= "465 " enableSsl="true" userName="noreply@domain.com" password="***" />
      </smtp>
    </mailSettings>
  </system.net>

回答1:

using (MailMessage mm = new MailMessage("Name <from@yandex.ru>", "to@site.com")){
    mm.Subject = "Mail Subject";
    mm.Body = "Mail Body";
    mm.IsBodyHtml = false;
    using (SmtpClient sc = new SmtpClient("smtp.yandex.ru", 25)){
        sc.EnableSsl = true;
        sc.DeliveryMethod = SmtpDeliveryMethod.Network;
        sc.UseDefaultCredentials = false;
        sc.Credentials = new NetworkCredential("from@yandex.ru", "YandexPassword");
        sc.Send(mm);
    }
}


回答2:

It seems that port 25 not work already. You can use port 587 with SmtpClient and yandex mail.