Email Code

What am I doing wrong here?

 private void SendMail(string from, string body)
    {
        string mailServerName = "plus.pop.mail.yahoo.com";
        MailMessage message = new MailMessage(from, "aditya15417@yahoo.com", "feedback", body);
        SmtpClient mailClient = new SmtpClient();
        mailClient.Host = mailServerName;
        mailClient.Send(message);
        message.Dispose();
    }

I got the following error:

The connection attempt failed because the connected party did not respond properly after some time or the connection was not established because the connected host could not respond 209.191.108.191:25

+3
source share
3 answers

You are using the wrong server . You will need to use the SMTP settings.

try this server: plus.smtp.mail.yahoo.comTheir site marks this host as SSL.

private void SendMail(string from, string body) 
{ 
    string mailServerName = "plus.smtp.mail.yahoo.com"; 
    int mailServerPort = 465;
    string toAddress = "aditya15417@yahoo.com";
    string subject = "feedback";

    string username = "user";
    string password = "password";

    SmtpClient mailClient = new SmtpClient(mailServerName, 
                                           mailServerPort); 
    mailClient.Host = mailServerName; 
    mailClient.Credentials = new NetworkCredential(username, 
                                                   password);
    mailClient.EnableSsl = true;

    using (MailMessage message = new MailMessage(from, 
                                                 toAddress, 
                                                 subject, 
                                                 body))
        mailClient.Send(message); 
} 
+5
source

You need to use an SMTP server, it looks like you are using a POP3 server.

+5

Yahoo EnableSSL = true SmtpClient.

, 465.

There are many tutorials on this site that really cover the use of the System.Net.Mail namespace:

0
source

Source: https://habr.com/ru/post/1739769/


All Articles