邮件可以有多个发件人吗? [英] Can a Message have multiple senders?

查看:170
本文介绍了邮件可以有多个发件人吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想检查谁通过JavaMail向我发送特定电子邮件时.

When I want to check who send a specific email to me with JavaMail.

我可以使用

Message.getFrom()

返回

Message[]

在什么情况下,已恢复的邮件可以具有来自其的多个身份?

In what circumstances can a revived Message have multiple Identities it came from?

关于 API 这对于传出电子邮件更有意义.

Regarding the API this makes more sense for outgoing Emails.

我真的可以这样吗?

Address from = message.getFrom()[0];

总是给我确切的1个消息发件人的地址吗?

Always gives me back exactly 1 Address which the Message was send from?

我现在已经实现了以下内容:

Address[] fromAddress = message.getFrom();

if (fromAddress == null || fromAddress.length > 1) {
    // Don't Process the Email and Notify me
}

推荐答案

是的,看来Message.getFrom()确实可以返回多个地址.

Yes, it seems that Message.getFrom() can really return multiple addresses.

我看了Apache Geronimo的JavaMail API实现的源代码,如果有多个From:标头或一个标头内有多个地址,它将返回多个地址.

I had a look at the sources for Apache Geronimo's implementation of the JavaMail API, and it will return multiple addresses if there are multiple From: headers, or multiple addresses inside one header.

关于这是否可能发生:

如Alex K.的回答所述,如果只有一个发件人",则标准允许多个发件人"地址.我不知道是否有人真的发送带有多个发件人"地址的邮件,但这是符合标准的.

As explained by Alex K.'s answer, the standard allows multiple "From" addresses if there is a single "Sender". I don't know whether anyone really sends mails with multiple "From" addresses, but it is standards-compliant.

实际发生的另一种情况:

Another situation which actually happens in practice:

某些垃圾邮件发送者显然发送带有多个From:标头的邮件.这不符合标准,但是显然某些邮件服务器仍接受该邮件.显然,这样做是为了获得过去的邮件过滤器,这些过滤器通过From:地址进行过滤.垃圾邮件发送者包括多个地址,希望当发现喜欢的带有发件人"地址的标头时,思想简单的过滤器将使邮件通过.

Some spammers apparently send mail with multiple From: headers. This is not standards-compliant, but apparently some mail servers still accept the mail. This is apparently done to get past mail filters that filter by the From: address. The spammers include multiple addresses in the hope that a simple-minded filter will let the message pass if it finds one header with a "From"-address it likes.

因此,总结:是的,您应该期望Message.getFrom()返回多个地址(或根本不返回).但是,您可能不需要花费很多精力来处理这种情况.也许您甚至可以仅将其记录为错误就可以摆脱困境-这取决于您的应用程序.

So in summary: Yes, you should expect Message.getFrom() to return multiple addresses (or none at all). However, you probably don't need to expend a lot of energy for handling that case. Maybe you can even get away with just logging it as an error - that depends on your application.

这篇关于邮件可以有多个发件人吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆