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
java mail issue
hi
in liferay ce 7.4 ga19
i use javax.mail in build.gradle
dependencies {
compileOnly group: "com.liferay.portal", name: "release.portal.api"
compileOnly group: "javax.mail", name: "javax.mail-api", version: "1.4.4"
cssBuilder group: "com.liferay", name: "com.liferay.css.builder", version: "3.0.2"
}
in service-builder module, it work fine, i can creating file and put it as attachment.
but in my mvc-module, it can not work when i add file
MailMessage mailMessage = new MailMessage();
InternetAddress from = new InternetAddress(Constant.DEFAULT_MAIL_SENDER_ADDRESS);
from.setPersonal(Constant.DEFAULT_MAIL_SENDER_PERSONAL);
mailMessage.setFrom(from);
mailMessage.setHTMLFormat(true);
mailMessage.setBody(message.toString());
mailMessage.setSubject("test notice");
mailMessage.setTo(internetAddressArrayList.toArray(new InternetAddress[internetAddressArrayList.size()]));
mailMessage.addFileAttachment(vmiInfoRecordFileData);
MailEngine.send(mailMessage);
same code, but it just doesn't work in portlet class when i add file attachment.
the exception
com.liferay.portal.kernel.log.LogSanitizerException: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; __ boundary="----=_Part_28_382286606.1651138290581" [Sanitized]
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:896) ~[?:1.8.0_202]
at javax.activation.DataHandler.writeTo(DataHandler.java:317) ~[?:1.8.0_202]
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1670) ~[mail.jar:1.6.6-SNAPSHOT]
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1889) ~[mail.jar:1.6.6-SNAPSHOT]
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1300) ~[mail.jar:1.6.6-SNAPSHOT]
at com.liferay.petra.mail.MailEngine._send(MailEngine.java:635) ~[com.liferay.petra.mail.jar:?]
i also try use api
public static void send(
InternetAddress from, InternetAddress[] to, InternetAddress[] cc,
InternetAddress[] bcc, InternetAddress[] bulkAddresses,
String subject, String body, boolean htmlFormat,
InternetAddress[] replyTo, String messageId, String inReplyTo,
List<FileAttachment> fileAttachments)
it doesn't work too.
but after i put
MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
mc.addMailcap("message/rfc822;; x-java-content- handler=com.sun.mail.handlers.message_rfc822");
befor i send it, it work.
i'd like know why same code have different response. thanks in advance.
Powered by Liferay™