开发者

code to send email

开发者 https://www.devze.com 2022-12-25 20:40 出处:网络
What am I 开发者_如何学编程doing wrong here? private void SendMail(string from, string body) {

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:

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


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 = "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); 
} 


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


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:

  • http://www.systemnetmail.com/
0

精彩评论

暂无评论...
验证码 换一张
取 消