9

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 with different ports (587, 465..) and SMTP hosts (smtp.yandex.com.tr, smtp.yandex.com, smtp.yandex.ru...) but I get the same error for all attempts.

SmtpClient sc = new SmtpClient("smtp.yandex.com.tr", 587);
//sc.Port = 587;
//sc.Host = "smtp.yandex.com";

sc.EnableSsl = false;
sc.Credentials = new System.Net.NetworkCredential(System.Configuration.ConfigurationManager.AppSettings["Email"].ToString(), 
                                                  System.Configuration.ConfigurationManager.AppSettings["Sifre"].ToString());
sc.UseDefaultCredentials = false;
sc.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user1688401
  • 1,851
  • 8
  • 47
  • 83

7 Answers7

10

I had same error and I correct it via doing some setting at mail.yandex.com (in email account)

To fix it; - Enter the mail address (mail.yandex.com) - Settings - Other Email application - Set selected POP3 setting that is all.

Note : I used 587 port and smtp.yandex.com.tr host.

Have a nice day :)

5

You must set sc.Credentials = new System.Net.NetworkCredential() after calling sc.UseDefaultCredentials = false;

UseDefaultCredentials = false will reset Credentials to null

try to switch lines order to:

sc.UseDefaultCredentials = false;
sc.Credentials = new System.Net.NetworkCredential(System.Configuration.ConfigurationManager.AppSettings["Email"].ToString(), 
                                                  System.Configuration.ConfigurationManager.AppSettings["Sifre"].ToString());

also valid settings for smtp.yandex.ru:

    smtpUserName=""
    enableSsl="true"
    smtpPassword=""
    smtpAuthentication="Basic"
    smtpServer="smtp.yandex.ru"
    smtpPort="465"
razon
  • 3,882
  • 2
  • 33
  • 46
3

Yandex Mail doesn't support connection without SSL (according to https://yandex.com/support/mail/mail-clients.xml). Try to set EnableSsl to true and use host: smtp.yandex.com, port: 465. If it will not work - try port 25

oryol
  • 5,178
  • 2
  • 23
  • 18
2

If it is a newly generated mail address, you must login with your browser and accept the agreement before trying to send email from C#. It was the case for me.

1

This error will happen if your password is wrong. That was the case for me at least.

Jorge.Methew
  • 75
  • 1
  • 10
1

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);
0

There are two spf records in cpanel Domains Manage/Manage Zone. Deleting one fixed it. just leave the yandex spf record, delete the other one, it will be fixed.