System.Net.Mail.MailMessage“回复”标头在 IIS 6.0 中被忽略,但在 IIS 5.1 中正常

发布于 2024-09-07 13:09:22 字数 4186 浏览 1 评论 0原文

我有一个在 WinXP 计算机 (IIS 5.1) 上开发和单元测试的 Web 应用程序项目。它已发布到Win2003Server (IIS 6.0)。该应用程序的一项功能会发送一封带有“回复”标题的电子邮件(下面是片段)。在 IIS 5.1 计算机上,回复正确显示在标头中。从 IIS 6.0 PC 发送时,标头不包含回复地址(见下文):

    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 机器(带有 IIS 5.1 的开发 PC)发送的收件人:

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

我什至设置了Win2003 计算机上的 VStudio2008 并在上面代码内的断点处停止,以确保邮件消息实际上已正确构建,并将“Reply-To”添加到标头(确实如此)。然而,当到达 Outlook 时,来自 MOJITO 服务器的邮件在标头中缺少“回复”。

是否存在其他配置问题会阻碍实际代码尝试执行的操作?

I have a web app project developed and unit-tested on a WinXP machine (IIS 5.1). It has been published to a Win2003Server (IIS 6.0). One feature of the app sends an email with a "Reply-To" header (snippet follows). On the IIS 5.1 machine, the Reply-To appears properly in the header. When sent from the IIS 6.0 PC, the header does not contain the Reply-To address (see below):

    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

The following internet headers are pasted from MS Outlook 2003 - View - Options:

Valid Reply-To as sent from JOHNXP machine (the dev PC with 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

Missing Reply-To as sent from the MOJITO machine (the 2003 server with IIS 6.0):

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

I even set up VStudio2008 on the Win2003 machine and stopped at a breakpoint inside the code above to make sure that the mailmessage was in fact being correctly built with the "Reply-To" added to the header (it is). Yet when arriving in Outlook, the message originating from the MOJITO server lacks the "Reply-To" in the header.

Are there other configuration issues that would thwart what the actual code is trying to do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

像你 2024-09-14 13:09:22

以下是我为解决此问题所做的更改:

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 

我从 Scott Mitchell 的这篇精彩文章中发现了这种替代编码方法:

"在 ASP.NET 2.0 中发送电子邮件:回复、优先级和已读回执"

似乎两种方法都应该有效,但现在是时候了继续前行。

Here is what I changed to fix this:

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 

I discovered this alternative coding approach from this great article by Scott Mitchell:

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

Seems like either method should work but it is time to move on.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文