aherlambang
aherlambang

Reputation: 14418

code to send email

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, "[email protected]", "feedback", body);
        SmtpClient mailClient = new SmtpClient();
        mailClient.Host = mailServerName;
        mailClient.Send(message);
        message.Dispose();
    }

I got the following error:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 209.191.108.191:25

Upvotes: 3

Views: 889

Answers (3)

rtpHarry
rtpHarry

Reputation: 13125

To send email using Yahoo mail servers you need to set EnableSSL = true on your SmtpClient instance.

You also need to use the correct port which is 465.

There are a lot of tutorials on this site which really cover how to use the System.Net.Mail namespace:

Upvotes: 0

Matthew Whited
Matthew Whited

Reputation: 22433

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

try this server: plus.smtp.mail.yahoo.com Their site notes this host as SSL.

private void SendMail(string from, string body) 
{ 
    string mailServerName = "plus.smtp.mail.yahoo.com"; 
    int mailServerPort = 465;
    string toAddress = "[email protected]";
    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); 
} 

Upvotes: 5

Fogh
Fogh

Reputation: 1295

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

Upvotes: 5

Related Questions