1

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

代码:

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

1 回答 1

3

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

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

于 2013-10-31T18:36:45.603 回答