2010-06-28 42 views
2

我有一個在WinXP機器(IIS 5.1)上開發和單元測試的web應用程序項目。它已發佈到Win2003Server(IIS 6.0)。該應用程序的一個功能發送一個「回覆」標題的電子郵件(摘錄如下)。在IIS 5.1機器上,答覆在頁眉中正確顯示。當從IIS 6.0 PC發送後,頭不包含的回覆地址(見下文):System.Net.Mail.MailMessage回覆標題在IIS 6.0中被忽略,但在IIS 5.1中是OK

Public Shared Sub SendEmail_withReplyTo(ByVal emailfrom As String, _ 
             ByVal emailto As String, _ 
             ByVal vbody As String, _ 
             ByVal vsubject As String, _ 
             ByVal msgcc As String, _ 
             ByVal msgbcc As String, _ 
             ByVal sReplyTo As String) 
    Dim MyMsg As New MailMessage 
    ErrorTrap.ErrorMsg = Nothing 
    With MyMsg 
     .From = New MailAddress(emailfrom) 
     .Headers.Add("Reply-To", sReplyTo) 
     .To.Add(emailto) 
     If msgcc.Length > 0 Then 
      .CC.Add(msgcc) 
     End If 
     If msgbcc.Length > 0 Then 
      .Bcc.Add(msgbcc) 
     End If 
     .Subject = vsubject 
     .IsBodyHtml = True 
     .Body = vbody 
    End With 
    Try 
     Dim smtp As New SmtpClient 
     smtp.Send(MyMsg) 
    Catch ex As Exception 
     ErrorTrap.ErrorMsg = Nothing 
     ErrorTrap.ErrorMsg = ex.ToString 
    End Try 
End Sub 

以下互聯網頭從MS Outlook 2003中粘貼 - 視圖 - 選項:

有效的回覆從JOHNXP機(dev的PC與IIS 5.1)發送:

Return-path: <[email protected]> 
Received: from JohnXP (unverified [10.10.30.66]) by mail.cbmiweb.com 
(Rockliffe SMTPRA 9.2.0) with ESMTP id <[email protected]>; 
Mon, 28 Jun 2010 15:16:25 -0400 
Message-ID: <[email protected]> 
Reply-To: [email protected] 
MIME-Version: 1.0 
From: [email protected] 
To: [email protected] 
Date: 28 Jun 2010 15:17:57 -0400 
Subject: Regarding your Ad #153949: Yard sale in vienna va June 12 at 8am 
Content-Type: text/html; charset=us-ascii 
Content-Transfer-Encoding: quoted-printable 

缺少回覆至從MOJITO機發送(與IIS 6.0的2003服務器):

Return-path: <[email protected]> 
Received: from MOJITO (unverified [10.10.30.14]) by mail.cbmiweb.com 
(Rockliffe SMTPRA 9.2.0) with ESMTP id <[email protected]>; 
Mon, 28 Jun 2010 13:37:53 -0400 
Message-ID: <[email protected]> 
MIME-Version: 1.0 
From: [email protected] 
To: [email protected] 
Date: 28 Jun 2010 13:39:25 -0400 
Subject: Regarding your Ad #153949: Yard sale in vienna va June 12 at 8am 
Content-Type: text/html; charset=us-ascii 
Content-Transfer-Encoding: quoted-printable 

我甚至成立VStudio2008在Win2003的機器上,並且在斷點處停止內上面的代碼,以確保該MAILMESSAGE實際上被正確地內置了「回覆「添加到標題(它是)。然而,當到達Outlook時,源自MOJITO服務器的消息在標題中缺少「回覆」。

是否有其他配置問題會阻止實際代碼嘗試執行的操作?

+0

昨天在一個有遺留代碼持久性的項目中遇到了這個問題。認爲這可能是這種情況。看起來最好在這裏相信抽象。謝謝您的幫助! – 2013-01-03 14:13:42

回答

5

這是我改變來解決這個:

Dim MyMsg As New MailMessage 
With MyMsg 
     .From = New MailAddress(emailfrom) 
     .ReplyTo = New MailAddress(sReplyTo) 'new code that fixed the problem 
     '.Headers.Add("Reply-To", sReplyTo)  'old code that works on WinXP IIS 5.1 

我發現這種替代由斯科特·米切爾編碼從這篇大文章的方法:

"Sending Email in ASP.NET 2.0: Reply-To, Priority, and Read Receipts"

好像這兩種方法應該工作,但現在是繼續前進的時候了。