gpt4 book ai didi

c# - 发送电子邮件的代码

转载 作者:行者123 更新时间:2023-11-30 13:42:37 24 4
gpt4 key购买 nike

我在这里做错了什么?

 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();
}

我收到以下错误:

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

最佳答案

您正在使用 wrong server .您将需要使用 SMTP 设置。

试试这个服务器:plus.smtp.mail.yahoo.com 他们的网站将这个主机标记为 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);
}

关于c# - 发送电子邮件的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2575159/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com