簡體   English   中英

使用SmtpClient發送時發送郵件異常失敗

[英]Failure sending mail Exception while send with SmtpClient

C#我正在嘗試使用以下代碼發送郵件。 操作系統是Windows 2008 Server。 SMTP已安裝。

           MailMessage message = new MailMessage();
            string[] recipientslist = recipients.Split(';');
            foreach (string recipient in recipientslist)
            {
                if (!String.IsNullOrEmpty(recipient))
                {
                    System.Net.Mail.MailAddress mailAddress = 
                        new System.Net.Mail.MailAddress(recipient);
                    message.To.Add(mailAddress.Address);
                }
            }
            message.From = new MailAddress(sender);
            message.Subject = subject;
            message.Body = body;
            SmtpClient smtpClient = new SmtpClient();
    smtpClient.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
    smtpClient.UseDefaultCredentials = true;
    smtpClient.Send(message);

在web.config中

  <system.net>
    <mailSettings>
      <smtp deliveryMethod="PickupDirectoryFromIis">
        <network host="localhost" port="25" defaultCredentials="true" />
      </smtp>
    </mailSettings>
  </system.net>

即使安裝了smtp,我也會遇到異常:發送郵件失敗。 堆棧跟蹤:位於System.Net.Mail.SmtpClient.Send(MailMessage消息)....

================================================== ========================================

未安裝SMTP的另一種情況是,它給我一個例外: 無法獲取IIS拾取目錄

任何幫助都是非常明顯的。

謝謝* 強文本 *

我得到了答案。

默認IIS拾取目錄需要權限。 我剛剛添加了網絡服務的權限並完成了。

以下是發送郵件之前應經過驗證的檢查清單。.http://torontoprogrammer.ca/2011/04/fixing-the-cannot-get-iis-pickup-directory-error-in-asp-net/

謝謝

這是一個防病毒程序QH Exchange Protection,會干擾從應用程序發送郵件。 請與您的系統管理員聯系。 如果您是系統管理員,則需要了解如何告訴Quick Heal產品不要執行此操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM