为什么方法Message.getFrom()返回一个数组?

Mar*_*ger 5 java email jakarta-mail

Javamail API有一个Massage类,它有一个getFrom()方法,你可以在这里找到:

https://javamail.java.net/nonav/docs/api/javax/mail/Message.html#getFrom()

关于这种方法的两个问题:

  1. 为什么它返回一个Address对象数组而不是一个Address对象?我想不出多个发件人发送邮件的情况.
  2. 该文档说,在某些实现中,它可能与实际发送消息的实体不同.有这样一个实现的例子吗?

Tob*_*ías 4

在标准RFC 5322 SMTP 中允许多个 FROM 地址

\n
\n

3.6.2. 发起者字段

\n

消息的发起者字段由发件人字段、发送者字段(如果适用)和可选的回复字段组成。发件人字段由字段名称“发件人”和一个或多个邮箱规范的逗号分隔列表组成。如果发件人字段在邮箱列表中包含多个邮箱规范,则包含字段名称“发件人”和单个邮箱规范的发件人字段必须出现在消息中。在任何一种情况下,还可以包括一个可选的回复字段,其中包含字段名称“回复”和一个或多个地址的逗号分隔列表。

\n

from = "发件人:" 邮箱列表 CRLF

\n
\n

看看 Michael Hampton 对这个服务器故障问题的回答:SMTP 允许多个发件人地址。这有用吗?为什么存在?

\n

正如他在回答中提到的:

\n
\n

RFC 822实际上给出了这种用法的示例。它要求\n使用时必须存在 Sender: 标头。

\n
\n

\xc2\xa0

\n
\n

A.2.7。委员会成员的代理人

\n
         George\'s secretary sends out a message which was authored\n    jointly by all the members of a committee.  Note that the name\n    of the committee cannot be specified, since <group> names  are\n    not permitted in the From field.\n \n        From:   Jones@Host,\n                Smith@Other-Host,\n                Doe@Somewhere-Else\n        Sender: Secy@SHost\n
Run Code Online (Sandbox Code Playgroud)\n
\n