Here you can find the source of getMailSender(MimeMessage message)
private static String getMailSender(MimeMessage message) throws MessagingException
//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(); } }