Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does method Message.getFrom() return an Array?

The Javamail API has a Massage class which has a getFrom() methode, as you can find here:

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

Two questions about this method:

  1. Why does it return an array of Address objects instead of just one Address object? I cannot think of a situation that a message is sent by more than one sender.
  2. The doc says that it may be different from the entity that actually sent the message, in some implementations. Is there an example of such an implementation?
like image 389
Martijn Burger Avatar asked Oct 27 '14 08:10

Martijn Burger


1 Answers

In the standard RFC 5322 SMTP allows multiple FROM addresses

3.6.2. Originator Fields

The originator fields of a message consist of the from field, the sender field (when applicable), and optionally the reply-to field. The from field consists of the field name "From" and a comma-separated list of one or more mailbox specifications. If the from field contains more than one mailbox specification in the mailbox list, then the sender field, containing the field name "Sender" and a single mailbox specification, MUST appear in the message. In either case, an optional reply-to field MAY also be included, which contains the field name "Reply-To" and a comma-separated list of one or more addresses.

from = "From:" mailbox-list CRLF

Take a look at Michael Hampton's answer to this serverfault question: SMTP allows for multiple from addresses. Was this ever useful, why does this exist?

As he mentions in his answer:

RFC 822 actually gives an example of this usage. It required that the Sender: header be present when it was used.

 

A.2.7. Agent for member of a committee

         George's secretary sends out a message which was authored
    jointly by all the members of a committee.  Note that the name
    of the committee cannot be specified, since <group> names  are
    not permitted in the From field.
 
        From:   Jones@Host,
                Smith@Other-Host,
                Doe@Somewhere-Else
        Sender: Secy@SHost
like image 144
Tobías Avatar answered Sep 27 '22 21:09

Tobías