Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SMTPFailedRecipientSexException不工作_C#_System.net.mail - Fatal编程技术网

C# SMTPFailedRecipientSexException不工作

C# SMTPFailedRecipientSexException不工作,c#,system.net.mail,C#,System.net.mail,我需要检查邮件是否已发送给现有收件人 这是我的密码 try { var smtpServer = new SmtpClient("smtp.gmail.com", 587) { Credentials = new System.Net.NetworkCredential(MAIL_FROM, PASSWORD), EnableSsl = true

我需要检查邮件是否已发送给现有收件人

这是我的密码

        try
        {
            var smtpServer = new SmtpClient("smtp.gmail.com", 587)
            {
               Credentials = new System.Net.NetworkCredential(MAIL_FROM, PASSWORD),
               EnableSsl = true
            };

            var mail = new MailMessage();
            mail.From = MAIL_FROM
            mail.To.Add(new MailAddress("nonexisting@gmail.com"));
            mail.Subject = title;
            mail.Body = content;
            smtpServer.Send(mailMessage);
        }
        catch (SmtpFailedRecipientsException ex)
        {
             //   never occures
        }
但是SmtpFailedRecipientsException在没有接收者时永远不会发生


有没有办法将SmtpServer配置为触发此异常?

问题是GMail没有说用户在SMTP事务期间无效。原因是垃圾邮件发送者通常会执行字典攻击,以查找“bob@gmail.com“和”tom@gmail.com,等等。任何未标记为“不存在”的地址都将是有效地址。因此,大多数SMTP服务器现在只接受SMTP事务期间的所有地址,或者静默删除无效地址,或者稍后发送跳出消息。无论哪种情况,代码中都无法确定这一点。

在源代码视图中
    in source view
    ------------------------------------------------------------------------------------------
            <html xmlns="http://www.w3.org/1999/xhtml">
            <head runat="server">
            <title>Send Mail using asp.net</title>
            </head>
            <body>
            <form id="form1" runat="server">
            <div>
            <table style=" border:1px solid" align="center">
            <tr>
            <td colspan="2" align="center">
            <b>Send Mail using asp.net</b>
            </td>
            </tr>
            <tr>
            <td>
            From:
            </td>
            <td>
            <asp:TextBox ID="txtFrom" runat="server"></asp:TextBox>
            </td>
            </tr>
            <tr>
            <td>
            Subject:
            </td>
            <td>
            <asp:TextBox ID="txtSubject" runat="server"></asp:TextBox>
            </td>
            </tr>
            <tr>
            <td>
            To:
            </td>
            <td>
            <asp:TextBox ID="txtTo" runat="server"></asp:TextBox>
            </td>
            </tr>
            <tr>
            <td valign="top">
            Body:
            </td>
            <td>
            <asp:TextBox ID="txtBody" runat="server" TextMode="MultiLine" Columns="30" Rows="10" ></asp:TextBox>
            </td>
            </tr>
            <tr>
            <td>
            </td>
            <td>
            <asp:Button ID="btnSubmit" Text="Send" runat="server" onclick="btnSubmit_Click" />
            </td>
            </tr>
            </table>
            </div>
            </form>
            </body>
            </html>
    ---------------------------------------------------------------------------------------In codeview
------------
         namespace  using system.net;
         btnSubmit_click(object sender,eventargs e)
        {
             MailMessage Msg = new MailMessage();
                // Sender e-mail address.
                Msg.From = txtFrom.Text;
                // Recipient e-mail address.
                Msg.To = txtTo.Text;
                Msg.Subject = txtSubject.Text;
                Msg.Body = txtBody.Text;
                // your remote SMTP server IP.
                SmtpMail.SmtpServer = "10.20.72.1";
                SmtpMail.Send(Msg);
                Msg = null;
                Page.RegisterStartupScript("UserMsg", "<script>alert('Mail sent thank you...');if(alert){ window.location='SendMail.aspx';}</script>");
                }
                catch (Exception ex)
                {
                Console.WriteLine("{0} Exception caught.", ex);
                }
------------------------------------------------------------------------------------------ 使用asp.net发送邮件 使用asp.net发送邮件 发件人: 主题: 致: 正文: ---------------------------------------------------------------------------------------在codeview中 ------------ 命名空间使用system.net; btnSubmit_单击(对象发送者,事件参数e) { MailMessage Msg=新的MailMessage(); //发件人电子邮件地址。 Msg.From=txtFrom.Text; //收件人电子邮件地址。 Msg.To=txtTo.Text; Msg.Subject=txtSubject.Text; Msg.Body=txtBody.Text; //您的远程SMTP服务器IP。 SmtpMail.SmtpServer=“10.20.72.1”; SmtpMail.Send(Msg); Msg=null; RegisterStartupScript(“UserMsg”,“alert('Mail sented thanky…');if(alert){window.location='SendMail.aspx';}”); } 捕获(例外情况除外) { WriteLine(“{0}捕获异常。”,ex); }
这就是您正在测试的电子邮件地址吗?你可能只是给我发了很多电子邮件吗nonexisting@gmail.com不nonexisting@gmail.com-这只是一个例子。我注意到在我的gmail账户中的Sent文件夹中有来自邮件传递子系统的邮件。有没有一种方法可以通过编程获取这些邮件,然后进行解析?你可以使用
IMAP
访问谷歌,谷歌将为你提供对已发送文件夹的访问权限。我建议你找一个IMAP库而不是自己的。这篇文章并没有用简洁的方式回答最初的问题,并且有几个编程语法错误需要纠正。