code发送电子邮件发送电子邮件、code

2023-09-05 02:23:44 作者:你那么骄傲╮

我在做什么错在这里?

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:

一个连接尝试失败,因为连接的方没有在一段时间后正确响应或已建立的连接失败,因为连接主机未能响应209.191.108.191:25

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

推荐答案

您正在使用的错误的服务器。您将需要使用SMTP设置。

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

试试这个服务器: plus.smtp.mail.yahoo.com 他们的网站上注意到,该主机SSL

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); 
} 
 
精彩推荐
图片推荐