C# yandex mail send error 5.5.4 Error: send AUTH command first

前端 未结 5 898
借酒劲吻你
借酒劲吻你 2021-01-15 06:14

I try to send mail using C# and yandex, but I get an error:

Error 5.5.4 Error: send AUTH command first

Here is my code. I try w

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-15 06:46

    I solve this problem my changing the SMTP host from smtp.yandex.com to smtp.yandex.ru and i was using port 25. Works for me perfectly. Here is the code:

    EmailCredentials credentials = new EmailCredentials();
        credentials.Domain = "domain.com";
        credentials.SMTPUser = "webmail@domain.com";
        credentials.SMTPPassword = "pass";
        int SmtpPort = 25;
        string SmtpServer = "smtp.yandex.ru";
    
        MailMessage EmailMsg = new MailMessage();
        EmailMsg.From = new MailAddress("webmail@domain.com", "Domain");
        EmailMsg.To.Add(new MailAddress("info@domain.mk", "info@domain.mk"));
        EmailMsg.ReplyToList.Add("info@domain.com");
    
        EmailMsg.Subject = "Welcome";
    
        EmailMsg.Body = "HTML body code";
    
        EmailMsg.IsBodyHtml = true;
        EmailMsg.Priority = MailPriority.Normal;
    
        System.Net.Mail.SmtpClient SMTP = new System.Net.Mail.SmtpClient();
        SMTP.Host = SmtpServer;
        SMTP.Port = SmtpPort;
        SMTP.EnableSsl = true;
        SMTP.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        SMTP.UseDefaultCredentials = false;
        SMTP.Credentials = new System.Net.NetworkCredential(credentials.SMTPUser, credentials.SMTPPassword);
    
        SMTP.Send(EmailMsg);
    

提交回复
热议问题