gpt4 book ai didi

c# - SMTP 客户端在 C# 应用程序中显示错误 "Requested action not taken"

转载 作者:行者123 更新时间:2023-11-30 14:17:49 25 4
gpt4 key购买 nike

我正在尝试使用 hotmail 帐户设置电子邮件发送应用程序。

代码如下所示:

MailMessage mail = new MailMessage(from, to);
mail.Subject = "Proba email";
mail.Attachments.Add(new Attachment("C:\\Documents and Settings\\Proba.txt"));
SmtpClient client = new SmtpClient();
client.UseDefaultCredentials = false;
client.Port = 587; // 465 568
client.Host = "smtp.live.com";
client.EnableSsl = true;
client.Credentials = new System.Net.NetworkCredential("smg@hotmail.com", "password");
client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
client.SendAsync(mail, "token");

使用异步我实际上没有得到任何错误,我什至收到反馈说消息已发送(事件触发器)但消息永远不会到达。如果我使用简单的 client.Send void,我会收到以下错误:

5.3.4 Requested action not taken; To continue sending messages, please sign in to your account.

那么关于问题可能是什么的任何想法?当我试图传递 hotmail 的 SMTP 设置时,我得到了各种设置,说端口 25,然后是 587,所以也许它在那里。非常感谢任何帮助!

  • 好的,现在肯定可以了,我想问一下我是否需要定期进行“我不是机器人检查”,还是一次性的事情?

最佳答案

这是我的设置,BTW async 不会返回任何错误。

<system.net>
<mailSettings>
<!-- E-mail server settings -->
<smtp from="do-not-reply@example.com">
<network host="smtp.example.com" port="25" userName="" password="" defaultCredentials="true" />
</smtp>
</mailSettings>

    void SendEmail(EmailEntity email)
{
var mailMessage = new MailMessage { From = new MailAddress(email.From) };
mailMessage.To.Add(new MailAddress(email.To));
mailMessage.Subject = email.Subject;
mailMessage.Body = email.Body;
mailMessage.IsBodyHtml = true;

// Send the email
var client = new SmtpClient();
client.Send(mailMessage);
}

关于c# - SMTP 客户端在 C# 应用程序中显示错误 "Requested action not taken",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5451899/

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