liferay发送邮件

在liferay中 有时候我们会想用系统配置的邮箱对外发送信件,实现方式如下:

1.在控制面板中配置好发送邮件的账号。

2.在代码中使用

String fromAddress =  PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_SMTP_USER);
		InternetAddress from = new InternetAddress(fromAddress);
		if (Validator.isNotNull(fromAddress) && Validator.isNotNull(emailAddress)) {
			InternetAddress to = new InternetAddress(emailAddress);
			System.out.println("fromAddress: " + fromAddress);
			MailEngine.send(from, to , subject , body);
			System.out.println("emailAddress: " + emailAddress);
		}

3.在portlet的WEB-INF/lib目录下加入commons-lang.jar 否则会报找不到org.apache.commons.lang.time.StopWatch的异常