Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
[Liferay 7.4.3] Error when sending a mail message with attachment
In previous versions, MailEngine.send(message) was used to send mail. But in version 7.4.3 this class is no longer available. If use MailServiceUtil.sendmail(message) to send a message with an attachment. That message is not sent because the attachments are passed as a File object ( contents in a temporary directory). And when the message is sent, the main stream has already been completed and the attachments from the temporary folder have already been deleted. How to correctly send messages with an attachment?
import com.liferay.mail.kernel.model.MailMessage;
import com.liferay.petra.mail.MailEngine;
MailMessage mailMessage = new MailMessage();
mailMessage.setHTMLFormat(true);
mailMessage.addFileAttachment(attachment);
MailEngine.send(mailMessage);
it works for me.
good luck
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™