Java Code Examples for javax.mail.internet.MimeMessage#getSender()

The following examples show how to use javax.mail.internet.MimeMessage#getSender() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeadersToHTTP.java    From james-project with Apache License 2.0 5 votes vote down vote up
private HashSet<NameValuePair> getNameValuePairs(MimeMessage message) throws UnsupportedEncodingException, MessagingException {

        // to_address
        // from
        // reply to
        // subject

        HashSet<NameValuePair> pairs = new HashSet<>();

        if (message != null) {
            if (message.getSender() != null) {
                pairs.add(new BasicNameValuePair("from", message.getSender().toString()));
            }
            if (message.getReplyTo() != null) {
                pairs.add(new BasicNameValuePair("reply_to", Arrays.toString(message.getReplyTo())));
            }
            if (message.getMessageID() != null) {
                pairs.add(new BasicNameValuePair("message_id", message.getMessageID()));
            }
            if (message.getSubject() != null) {
                pairs.add(new BasicNameValuePair("subject", message.getSubject()));
            }
            pairs.add(new BasicNameValuePair("size", Integer.toString(message.getSize())));
        }

        pairs.add(new BasicNameValuePair(parameterKey, parameterValue));

        return pairs;
    }
 
Example 2
Source File: FakeMail.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Override
public void setMessage(MimeMessage message) {
    this.msg = message;
    try {
        if (message != null && message.getSender() != null) {
            this.sender = new MailAddress((InternetAddress) message.getSender());
        }
    } catch (MessagingException e) {
        throw new RuntimeException("Exception caught", e);
    }
}