SMTP 客户端显示错误“未采取请求的操作”在 C# 应用程序中

发布于 2024-10-27 05:53:48 字数 1118 浏览 3 评论 0原文

我正在尝试使用 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("[email protected]", "password");
        client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
        client.SendAsync(mail, "token");

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

5.3.4 未采取请求的行动;要继续发送消息,请登录您的帐户。

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

  • 好的,现在肯定可以正常工作了,我只是想问一下,我是否必须定期进行“我不是机器人检查”,还是一次性的事情?

I am trying to setup an email sending application, using a hotmail account.

The code looks like this:

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("[email protected]", "password");
        client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
        client.SendAsync(mail, "token");

Using, Async I actually get no errors, I even get the feedback saying message sent (Event triggers) but the message never arrives. If I use the simple client.Send void, I get the following error:

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

So any ideas on what the problem can be? As I was trying to hand down the SMTP settings of hotmail I got various setups saying port 25, then 587 so maybe it's something there. Any help would be greatly appreciated thanks!

  • Okay so it's definitely working now, I would just like to ask if I will have to do regular "I'm not a robot checks" or was that a one-time thing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

命比纸薄 2024-11-03 05:53:48

这是我的设置,顺便说一句,异步不会返回任何错误。

<system.net>
<mailSettings>
  <!-- E-mail server settings -->
  <smtp from="[email protected]">
    <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);
    }

Here is my setup, BTW async will not return any errors.

<system.net>
<mailSettings>
  <!-- E-mail server settings -->
  <smtp from="[email protected]">
    <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);
    }
べ繥欢鉨o。 2024-11-03 05:53:48

我有一个类似的设置,我只使用对我有用的 Send() 。我唯一额外的东西

 client.DeliveryMethod = SmtpDeliveryMethod.Network;

就在 client.Send(); 之前。不确定仅此是否可以解决您的问题。您是否使用相同的服务器和凭据设置了 Outlook?

I have a similar setup where I just use Send() that is working for me. The only thing extra that I have is

 client.DeliveryMethod = SmtpDeliveryMethod.Network;

just before client.Send();. Not sure if this alone will solve your problem. Do you have outlook setup with the same server and credentials ?

迎风吟唱 2024-11-03 05:53:48
SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();

        try
        {
           // System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
            MailAddress fromAddress = new MailAddress(txt_name.Text, txt_to.Text);


            smtpClient.Host = "smtp.gmail.com";


            smtpClient.Port = 25;

           // msg.From = new System.Net.Mail.MailAddress("[email protected]");

          message.From = fromAddress;

            message.To.Add("[email protected]");


            message.Body = txt_des.Text;
            smtpClient.EnableSsl = true;

            System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();

            NetworkCred.UserName = "[email protected]";

            NetworkCred.Password = "xtz";

            smtpClient.UseDefaultCredentials = true;

            smtpClient.Credentials = NetworkCred; 


            smtpClient.Send(message);

            lblStatus.Text = "Email successfully sent.";
        }
        catch (Exception ex)
        {
            lblStatus.Text = "Send Email Failed." + ex.Message;
        }
SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();

        try
        {
           // System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
            MailAddress fromAddress = new MailAddress(txt_name.Text, txt_to.Text);


            smtpClient.Host = "smtp.gmail.com";


            smtpClient.Port = 25;

           // msg.From = new System.Net.Mail.MailAddress("[email protected]");

          message.From = fromAddress;

            message.To.Add("[email protected]");


            message.Body = txt_des.Text;
            smtpClient.EnableSsl = true;

            System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();

            NetworkCred.UserName = "[email protected]";

            NetworkCred.Password = "xtz";

            smtpClient.UseDefaultCredentials = true;

            smtpClient.Credentials = NetworkCred; 


            smtpClient.Send(message);

            lblStatus.Text = "Email successfully sent.";
        }
        catch (Exception ex)
        {
            lblStatus.Text = "Send Email Failed." + ex.Message;
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文