2011-03-21

[Asp.Net]在沒有SMTP的情況下確認發信的程式

.Net 2.0之後提供了一個specifiedPickupDirectory的功能,
讓你在沒有SMTP server的情況下使用資料夾來儲存發信的內容.

使用方式就是在web.config中加入以下的設定

<system.net>
 <mailSettings>
  <smtp deliveryMethod="SpecifiedPickupDirectory">
   <specifiedPickupDirectory pickupDirectoryLocation="C:\MailPickup\" />
  smtp>
 mailSettings>
system.net>

設定完後,發送的信件就會存在指定的資料夾中.

update [2012/02/23] :

如果你是使用在.net 4.0的話,有可能設定完後出現下面這錯誤

The SMTP host was not specified.

這是個已知的問題 :
http://connect.microsoft.com/VisualStudio/feedback/details/539160/smtpclient-reports-invalidoperationexception-when-disposed-immediatelly-after-sending-mail-and-pickup-directory-is-used

而臨時的解決的方式是在Smtp的tag下加個


<network host="localhost" />

完整範例 :
<system.net>
 <mailSettings>
   <smtp deliveryMethod="SpecifiedPickupDirectory">
     <network host="localhost" />
     <specifiedPickupDirectory pickupDirectoryLocation="C:\MailPickup\" />
     smtp>
 mailSettings>
system.net>



沒有留言:

在Hyper-V上跑ubuntu 22.04 Desktop, 裝完後一登入就凍住

如果你也遇到這情況, 你可以執行以下步驟 按 Ctrl+Alt+F3 進入 virtual console. (按Ctrl+Alt+F1 可以再回到GUI) 登入後執行下面指令 (更新kernel) * sudo add-apt-repository ppa:capp...