Skip to content

Instantly share code, notes, and snippets.

@CorneAussems
Created May 19, 2022 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CorneAussems/135721a425c7bb38a731e025c691cbcc to your computer and use it in GitHub Desktop.
Save CorneAussems/135721a425c7bb38a731e025c691cbcc to your computer and use it in GitHub Desktop.
Liferay 7.2 Send Email
import com.liferay.mail.kernel.service.MailServiceUtil;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import com.liferay.mail.kernel.model.MailMessage;
import com.liferay.portal.util.*
try {
property = "mail.throws.exception.on.failure";
PropsUtil.set(property,"true")
println("property:"+PropsUtil.get(property))
now = new java.util.Date();
InternetAddress fromAddress = new InternetAddress("system_admins_ams@valamis.com");
InternetAddress toAddress = new InternetAddress("corne.aussems@valamis.com");
MailMessage mailMessage = new MailMessage();
mailMessage.setTo(toAddress);
mailMessage.setFrom(fromAddress);
mailMessage.setSubject("Testing mail with Plain Text "+now);
mailMessage.setBody("This Mail Comes From Liferay "+now);
MailServiceUtil.sendEmail(mailMessage);
System.out.println("Send mail with Plain Text "+now);
println("Send mail with Plain Text "+now);
} catch (AddressException e) {
println(e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment