Here you can find the source of getSenderEmail(MimeMessage msg)
Parameter | Description |
---|---|
msg | Description of the Parameter |
public static String getSenderEmail(MimeMessage msg)
//package com.java2s; /*//w w w . j a v a 2 s . c o m * Copyright 1999-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import javax.mail.MessagingException; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class Main { /** * Description of the Field */ public final static String SENDER_NOT_AVAILABLE = "-not available-"; /** * Gets the senderEmail attribute of the MimeMessageUtil class * *@param msg Description of the Parameter *@return The senderEmail value */ public static String getSenderEmail(MimeMessage msg) { String senderEmail = null; try { InternetAddress[] from = (InternetAddress[]) msg.getFrom(); if (from != null && from.length > 0) { senderEmail = from[0].getAddress(); } } catch (AddressException e) { senderEmail = SENDER_NOT_AVAILABLE; } catch (MessagingException e) { senderEmail = SENDER_NOT_AVAILABLE; } if (senderEmail == null || senderEmail.trim().length() == 0) { senderEmail = SENDER_NOT_AVAILABLE; } return senderEmail; } }