【问题标题】:Smtp.Send throws no error when reciepent has incorrect email address当收件人的电子邮件地址不正确时,Smtp.Send 不会引发错误
【发布时间】:2013-10-31 18:13:18
【问题描述】:

我正在使用SmtpClient.Send Method 发送电子邮件,但是当我尝试发送到一个不存在的电子邮件帐户时,Send 方法没有抛出异常,我如何判断收件人邮件地址是否有效,或者邮件不会' t 到达,或检测到此问题。

代码:

            Properties.Settings appSettings = new Properties.Settings();
            MailMessage message = new MailMessage();

            message.From = new MailAddress(appSettings.senderMail);        
            message.Subject = appSettings.mailsubj;
            message.Body = appSettings.mailbody;
            Attachment attach = new Attachment(sOutput);
            message.Attachments.Add(attach);

            SmtpClient client = new SmtpClient(appSettings.SMTP);

            client.SendCompleted += this.SendCompletedCallback;
            foreach (String clientEmail in clientEmailList)
            {
                message.To.Clear();
                message.To.Add(clientEmail);
                //client.Send(message);

                try
                {
                    client.Send(message);
                    AddToLog(String.Format("\t{0}{1}", Properties.Resources.ResourceManager.GetString("MAIL_SEND_SUCCESS"), clientEmail));
                }
                catch (SmtpFailedRecipientException ex)
                {
                    AddToLog(String.Format("\t{0}{1}:\n\t{2}", Properties.Resources.ResourceManager.GetString("MAIL_SEND_ERROR"), clientEmail, ex.Message));
                }
                catch (SmtpException smtp_Ex)
                {
                    AddToLog(String.Format("\t{0}{1}:\t{2}", Properties.Resources.ResourceManager.GetString("MAIL_SEND_ERROR"), clientEmail, "Cannot connect to SMTP server."));
                }
                catch (Exception ex)
                {
                    AddToLog(String.Format("\t{0}{1}:\n\t{2}", Properties.Resources.ResourceManager.GetString("MAIL_SEND_ERROR"), clientEmail, ex.Message));
                }
              //  client.SendAsync(message, clientEmail);
            }

【问题讨论】:

标签: c# .net smtp


【解决方案1】:

当 SMTP 客户端发送消息时,它不知道电子邮件地址的有效性,如果该地址属于域,则与 SMTP 服务器的域不同。

只有在您的 SMTP 服务器尝试将邮件从另一个域传递给收件人之后,才能知道这一点。通常,在这种情况下,您会收到一条错误消息。

【讨论】:

  • 我想显示和错误,在这种情况下,我如何找到它以便我可以显示一条消息说邮件尚未送达
  • 您无法使用 SMTP 同步执行此操作。从 SMTP 客户端发送邮件。
  • @A.K: My answer to a similar question 解释得更详细一点。
  • 我明白,但是有没有一种可能的方式与服务器交互,询问他邮件是否已成功发送,或者我想要实现的解决方法?
  • @A.K:一般情况下,不会。传递消息或确定消息无法传递可能需要任意时间(毫秒到几天)。对于无法投递的消息,通知(如果已发送)是通过将电子邮件发送回发件人地址来完成的。但不要求服务器发送此类通知。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-23
  • 2016-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-08
相关资源
最近更新 更多