Java Code Examples for javax.mail.internet.AddressException#printStackTrace()

The following examples show how to use javax.mail.internet.AddressException#printStackTrace() . 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: MailUtils.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 用来取得 Email 地址的友好称呼。
 * @param emailAddress
 *            	Email 地址
 * @return String
 * 				例如: emailAddress="John <[email protected]>" 就返回 John。
 */

public static String getAddressName(String emailAddress) {
	String result = "";
	if (emailAddress == null) {
		return result;
	}
	try {
		InternetAddress address = new InternetAddress(emailAddress);
		String text = address.getPersonal();
		if (text == null) {
			result = emailAddress;
		} else {
			result = text;
		}
	} catch (AddressException e) {
		e.printStackTrace();
		return emailAddress;
	}
	return result;
}
 
Example 2
Source File: MailUtils.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 用来取得 Email 地址。
 * @param emailAddress
 *            the email address
 * @return String
 * 				例如: emailAddress="John <[email protected]>" 就返回 [email protected]
 */
public static String getAddress(String emailAddress) {
	String result = "";
	if (emailAddress == null) {
		return result;
	}
	try {
		InternetAddress address = new InternetAddress(emailAddress);
		String text = address.getAddress();
		if (text == null) {
			result = emailAddress;
		} else {
			result = text;
		}
	} catch (AddressException e) {
		e.printStackTrace();
		return emailAddress;
	}
	return result;
}
 
Example 3
Source File: MailUtils.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 用来取得 Email 地址的友好称呼。
 * @param emailAddress
 *            	Email 地址
 * @return String
 * 				例如: emailAddress="John <[email protected]>" 就返回 John。
 */

public static String getAddressName(String emailAddress) {
	String result = "";
	if (emailAddress == null) {
		return result;
	}
	try {
		InternetAddress address = new InternetAddress(emailAddress);
		String text = address.getPersonal();
		if (text == null) {
			result = emailAddress;
		} else {
			result = text;
		}
	} catch (AddressException e) {
		e.printStackTrace();
		return emailAddress;
	}
	return result;
}
 
Example 4
Source File: MailUtils.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 用来取得 Email 地址。
 * @param emailAddress
 *            the email address
 * @return String
 * 				例如: emailAddress="John <[email protected]>" 就返回 [email protected]
 */
public static String getAddress(String emailAddress) {
	String result = "";
	if (emailAddress == null) {
		return result;
	}
	try {
		InternetAddress address = new InternetAddress(emailAddress);
		String text = address.getAddress();
		if (text == null) {
			result = emailAddress;
		} else {
			result = text;
		}
	} catch (AddressException e) {
		e.printStackTrace();
		return emailAddress;
	}
	return result;
}
 
Example 5
Source File: MailComponent.java    From awacs with Apache License 2.0 5 votes vote down vote up
Group(String[] addr) {
    this.recipients = new Address[addr.length];
    for (int i = 0; i < addr.length; i++) {
        try {
            this.recipients[i] = new InternetAddress(addr[i]);
        } catch (AddressException e) {
            e.printStackTrace();
        }
    }
}
 
Example 6
Source File: MailSenderTest.java    From Ardulink-1 with Apache License 2.0 5 votes vote down vote up
@Before  
  public void setUp() {  
  	try {
	address = new InternetAddress("[email protected]");
} catch (AddressException e) {
	e.printStackTrace();
}
  	assertNotNull(address);
  	subject = "test message";
body = "this is a test message body";
  }
 
Example 7
Source File: MailUtil.java    From FoxBPM with Apache License 2.0 5 votes vote down vote up
private Address[] getAddress(String[] add) {
	Address[] a = new Address[add.length];
	for (int i = 0; i < add.length; i++) {
		try {
			a[i] = new InternetAddress(add[i]);
		} catch (AddressException e) {
			LOGGER.error("地址出现异常", e);
			e.printStackTrace();
		}
	}
	return a;
}
 
Example 8
Source File: SendEmailController.java    From oncokb with GNU Affero General Public License v3.0 4 votes vote down vote up
private static Boolean sendFromGMail(String from, String pass, String[] to, String subject, String body) {
    Properties props = System.getProperties();
    String host = "smtp.gmail.com";
    props.put("mail.smtp.starttls.enable", "true");
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.user", from);
    props.put("mail.smtp.password", pass);
    props.put("mail.smtp.port", "587");
    props.put("mail.smtp.auth", "true");

    Session session = Session.getDefaultInstance(props);
    MimeMessage message = new MimeMessage(session);

    try {
        message.setFrom(new InternetAddress(from));
        InternetAddress[] toAddress = new InternetAddress[to.length];

        // To get the array of addresses
        for( int i = 0; i < to.length; i++ ) {
            toAddress[i] = new InternetAddress(to[i]);
        }

        for( int i = 0; i < toAddress.length; i++) {
            message.addRecipient(Message.RecipientType.TO, toAddress[i]);
        }

        message.setSubject(subject);
        message.setText(body);
        Transport transport = session.getTransport("smtp");
        transport.connect(host, from, pass);
        transport.sendMessage(message, message.getAllRecipients());
        transport.close();
        return true;
    }
    catch (AddressException ae) {
        ae.printStackTrace();
    }
    catch (MessagingException me) {
        me.printStackTrace();
    }

    return false;
}