1

I'm unable to send an email using the yahoo client. The same code & port works fine with gmail credentials.

Testing this in my local system.

var fromAddress = new MailAddress("myname@yahoo.com", "My Name");
                    var toAddress = new MailAddress("validemail@yahoo.com", "");

                    var smtp = new SmtpClient
                    {
                        Host = "smtp.mail.yahoo.com",
                        Port = 587,
                        EnableSsl = false,
                        DeliveryMethod = SmtpDeliveryMethod.Network,
                        UseDefaultCredentials = false,
                        Credentials = new NetworkCredential(fromAddress.Address, "P@s5word")
                    };

                    using (var message = new MailMessage(fromAddress, toAddress)
                    {
                        Subject = emailSubject,
                        Body = emailBody,
                        IsBodyHtml = true
                    })
                    {
                        //turning the security off for testing
                        ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
                        { return true; };
                        smtp.Send(message);
                    }

Also tried by enabling the SSL, with no luck.

UPDATE:

I realize that oAuth2 needs to be used in this case. I have created an app in Yahoo for my project and have the client ID and client secret.

I'm unable to find any info on how to use these details to send an email using Yahoo.

sukesh
  • 2,379
  • 12
  • 56
  • 111
  • 2
    You need to use OAuth2 authentication since Yahoo changed the policy to send mail with credentials (see [this issue](https://stackoverflow.com/questions/52527061/system-net-mail-smtpexception-mailbox-unavailable-the-server-response-was-re)), and possibly require additional OAuth library. – Tetsuya Yamamoto Nov 19 '18 at 06:08
  • @TetsuyaYamamoto Could you pls help me with a code sample for sending email with yahoo using oauth. I'm unable to find any. The ones that are, only talk about getting accesstoken and i do not know how to proceed after that. Thank you. – sukesh Nov 19 '18 at 06:55

2 Answers2

1

Other than using oAuth2, you can also activate access to less secure apps within your Yahoo account here: https://login.yahoo.com/account/security

SmtpClient will work normally. But you will be repititve rembembered from Yahoo to deactivate it again.

python_kaa
  • 1,034
  • 13
  • 27
0

Need to create an App password from this url https://login.yahoo.com/account/security

Click on Manage App password: Select app type (Other if you don't know) Click to generate Copy the password and use this password as a login password while sending an email.