设置电子邮件标头,以便退回的电子邮件转到特定地址

发布于 2024-10-22 10:01:42 字数 649 浏览 6 评论 0原文

从我们的 Rails 应用程序中,我们发送一些系统生成的电子邮件,其“发件人”地址设置为 [电子邮件受保护]。如果这些邮件被退回,我们的邮件服务器会将其发送回该地址。但是,我想做的是不要将退回的电子邮件发送回 [email  ;protected] 但发送到不同的地址,例如 [email protected]< /a>.

我是否可以在电子邮件中设置标头或其他内容来实现此目的,而无需我去调查我们的电子邮件服务器的变幻莫测?如果相关的话,我们会使用 exim 发送邮件。

干杯,最大

From our rails app we send out some system-generated emails with the 'from' address set to [email protected]. If these bounce they get sent back to this address by our mail server. However, what i'd like to do is to not have bounced emails get sent back to [email protected] but to a different address, such as [email protected].

Is there a header or something i can set in the email that will achieve this, without me having to go and investigate the vagaries of our email server? We send the mails out using exim in case that's relevant.

cheers, max

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

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

发布评论

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

评论(5

烟─花易冷 2024-10-29 10:01:42

在阅读了很多有关 exim 配置的内容后,我自己在 exim4 中发现了这一点。

首先,您希望您的应用程序添加以下标头:

Return-Path: <[email protected]>

使用或不使用括号均可。无论哪种方式,Exim 都会在末尾添加括号。

其次,这是最困难的部分。 Exim 总是想用发送它的 unix 用户来覆盖我的 Return-Path: 地址。您可以在 Ubuntu 中使用 /etc/email-addresses 为 Web 应用程序的用户设置静态电子邮件,但这仍然会忽略 Return-Path 标头。以下是我如何修改我的 exim 配置以尊重 Web 应用程序的返回路径:

在主配置区域中添加:

return_path_remove = false

在适当的路由器配置中(例如 dnslookup):

dnslookup:
  # ...
  errors_to = ${if def:h_return-path: {${address:$h_return-path:}} fail}
  headers_remove = return-path
  no_more

现在 exim 应该复制信封上的返回路径标头地址 -级别并删除原始 Return-Path 标头。

我尝试了很多其他配置指令,这是真正对我有用的唯一方法。

I just figured this out myself in exim4 after a lot of reading about exim configuration.

First, you want your app to add the following header:

Return-Path: <[email protected]>

Works with or without brackets. Exim will add brackets in the end either way.

Second, this was the hard part. Exim always wanted to override my Return-Path: address with the unix user who sent it. You can use /etc/email-addresses in Ubuntu to set a static email for the user of your web app, but this still ignores the Return-Path header. Here is how I modified my exim config to respect the Return-Path from the web app:

In the main config area add:

return_path_remove = false

In the appropriate router config (e.g. dnslookup):

dnslookup:
  # ...
  errors_to = ${if def:h_return-path: {${address:$h_return-path:}} fail}
  headers_remove = return-path
  no_more

Now exim should copy the Return-Path header address at the envelope-level and delete the original Return-Path header.

I tried lots of other configuration directives and this is the only way that actually worked for me.

攒眉千度 2024-10-29 10:01:42

晚了三年,但以防万一其他人也这样过来。 Return-Path 是正确的标头,但正如 James Garriss 上面指出的那样,它必须由执行最终交付的站点放置在那里。你不能只把它粘在自己身上。

如果您通过直接连接到 SMTP 服务器来编写电子邮件,那么这很简单 - MAIL 命令包含返回路径。如果您发送

MAIL FROM:<[email protected]>

到 SMTP 服务器,则退回邮件将返回到 [email protected]

如果您不构建 SMTP,并且正在运行 MTA(即 exim/etc),那么您必须为 MTA 找到命令行开关。对于 sendmail,-f [电子邮件受保护] “设置发件人地址”,这最终作为最终发送的邮件中的 Return-Path[email protected] 将被退回(我对自动生成的电子邮件正是这样做的)。我还没有在 exim 上尝试过这个,但它有完全相同的选项,并且应该可以工作。

3 years too late, but just in case anyone else comes this way. Return-Path is the right header but, as James Garriss pointed out above, it has to be placed there by the site performing final delivery. You can't just stick it in yourself.

If you're writing emails by connecting directly to an SMTP server then this is easy - the MAIL command contains the return path. If you send

MAIL FROM:<[email protected]>

to the SMTP server then bounces will be returned to [email protected].

If you're not constructing SMTP, and you're running an MTA (ie. exim/etc), then you have to find a command-line switch for your MTA. For sendmail, -f [email protected] "sets the sender's address", and this ends up as the Return-Path in the final delivered mail, and [email protected] will get the bounces (I do exactly this for auto-generated emails). I haven't tried this on exim, but it has exactly the same option, and it should work.

帅气称霸 2024-10-29 10:01:42

Return-Path 标头由接收服务器写入,而不是由发送服务器写入。根据 RFC 5321,它与MAIL FROM 命令中提供的地址。

即使您自己设置了 Return-Path 标头,接收服务器也会覆盖该标头。

现在,事情是这样的,MAIL FROM 命令中的地址和 From 标头中的地址可以不同。接收用户看不到 MAIL FROM 地址。他们只能看到 From 标头地址。

因此,如果您想忽略退回邮件或希望它们发送至特定地址,则应在 MAIL FROM 命令中使用该地址。

但在 From 标头中,您只需使用 [ email protected] - 用户将看到此地址。


为了进一步简化,您可以从 [电子邮件受保护] 地址。接收服务器会将退回邮件发送到该地址。

向您的用户显示[电子邮件受保护]地址而不是 handle_bounce... 地址,请将原始电子邮件 MIME 消息中的 From 标头设置为 noreply... 地址。


我最近收到一封来自 Bitbucket 的未回复电子邮件。这是原始消息:

Return-Path: <bounce-1231860_HTML-1209402755-103116181-132689-225@bounce.mailer.atlassian.com>
From: "Atlassian Bitbucket" <[email protected]>
To: <[email protected]>
Subject: Continuous delivery, without the headache.
Date: Wed, 28 Feb 2018 12:40:53 -0600
MIME-Version: 1.0
Reply-To: "Atlassian Bitbucket" <reply-fe3915707665057b741c71-1231860_HTML-1209402755-132689-225@mailer.atlassian.com>

... message body ...

如您所见,Return-Path 是专用于处理退回邮件的地址。但From 地址是noreply@... 邮件。这意味着这封电子邮件实际上是由该退回处理地址发送的,而不是由 noreply 地址发送的。

您还可以看到 Reply-To 标头,该标头专门用于在用户回复无回复电子邮件时处理回复。这些回复可能会立即被丢弃。

Return-Path header is written by the receiving server, not by the sending server. And as per the RFC 5321, it is the same as the address supplied in MAIL FROM command.

Even if you set the Return-Path header yourself, the receiving server will overwrite that.

Now, here's the thing, the address in the MAIL FROM command and the address in the From header can be different. The receiving user does not see the MAIL FROM address. They only see the From header address.

So, if you want to ignore the bounces or want them to go to a specific address, you should use that address in the MAIL FROM command.

But in the From header, you can just use [email protected] - the user will see this address.


To simplify a bit more, you send the email from [email protected] address. The receiving server will send the bounces to this address.

To show your user the [email protected] address instead of handle_bounce... address, set the From header in the raw email MIME message to the noreply... address.


I recently got a no-reply email from Bitbucket. Here's the raw message:

Return-Path: <bounce-1231860_HTML-1209402755-103116181-132689-225@bounce.mailer.atlassian.com>
From: "Atlassian Bitbucket" <[email protected]>
To: <[email protected]>
Subject: Continuous delivery, without the headache.
Date: Wed, 28 Feb 2018 12:40:53 -0600
MIME-Version: 1.0
Reply-To: "Atlassian Bitbucket" <reply-fe3915707665057b741c71-1231860_HTML-1209402755-132689-225@mailer.atlassian.com>

... message body ...

As you can see, the Return-Path is an address dedicated to handle bounces. But the From address is a noreply@... mail. What that means is this email was actually sent by this bounce handling address, not by the noreply address.

You can also see the Reply-To header, which is dedicated to handle replies, if a user replies to no-reply emails. Those replies are probably discarded right away.

风情万种。 2024-10-29 10:01:42

Errors-To 已被弃用,因此邮件服务器通常会忽略此标头 - 大多数服务器会将意愿退回到“信封发件人”。

这是您的邮件客户端作为连接的一部分发送的电子邮件地址SMTP 服务器(不一定是发件人地址 - 尽管通常是相同的)。

我不太了解 Rails,但我发现 this - 不过,据我所知,Return-Path 是由 MTA 重置的,以匹配来自客户端的 MAIL FROM 信息,所以看来您实际上无法设置它。

我认为你唯一能做的就是在你的服务器中设置退回地址。

Errors-To is deprecated, so mail servers will typically ignore this header - most servers will bounce will to the 'envelope sender'.

This is the email address that your mail client sends as part of the connection to the SMTP server (not necessarily the From address - though it typically is the same).

I don't know Rails all that well, but I found this - although, as far as I can tell Return-Path is reset by MTAs to match the MAIL FROM information from the client, so it seems you can't actually set it.

I think the only thing you can do is set the bounce address in your server.

初雪 2024-10-29 10:01:42

解决方案如下:

在电子邮件标题中,您可以设置:

From: "From Name" <[email protected]>
Reply-To: [email protected]

Errors-To: <[email protected]>
Return-Path: <[email protected]>

Here is the solution:

In the email header you can set:

From: "From Name" <[email protected]>
Reply-To: [email protected]

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