Java Email Send getMailSender(MimeMessage message)

Here you can find the source of getMailSender(MimeMessage message)

Description

Returns Mail Sender from the message

License

Open Source License

Declaration

private static String getMailSender(MimeMessage message) throws MessagingException 

Method Source Code

//package com.java2s;

import javax.mail.MessagingException;

import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Main {
    /**/*from   ww w.  j a  v  a  2 s  . c  o  m*/
     * Returns Mail Sender from the message
     *
     * @return
     */
    private static String getMailSender(MimeMessage message) throws MessagingException {

        //get it from sender
        InternetAddress sender = (InternetAddress) message.getSender();

        if (sender == null) {
            //get it From
            InternetAddress[] fromAddress = (InternetAddress[]) message.getFrom();
            if (fromAddress != null & fromAddress.length > 1) {
                return (fromAddress[0]).getAddress();
            }
            return null;
        }
        return sender.getAddress();
    }
}

Related

  1. getSenderEmail(MimeMessage msg)
  2. send(final String username, final String password, final String toEmail, final String subject, final String content)
  3. send(String from, String to, String bcc, String subject, String content)
  4. send(String to, String from, String subject, String text, Properties mailProps)