Created
May 19, 2022 15:13
-
-
Save CorneAussems/135721a425c7bb38a731e025c691cbcc to your computer and use it in GitHub Desktop.
Liferay 7.2 Send Email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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