I can send emails just fine but the attachment is never added to the mail. Below is my code, created a tempFile for testing purpose.
What did i miss?
I tried other ways to add attachments as well creating a seperate BodyPart, using FileInputStreamResource,...
MimeMessage msg = sender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(msg, true, "UTF-8");
helper.setFrom(eMail);
helper.setTo(eMail);
helper.setSubject(subject);
msg.setContent(message, "text/html");
File randomFile = File.createTempFile("rnd", "txt");
randomFile.deleteOnExit();
helper.addAttachment("rnd", randomFile);
sender.send(msg);
Any help is appreciated
使用MimeMessage而不是MimeMessage设置消息内容。从msg.setContent(message,“ text / html”)更改为helper.setText(message,true)。使用MimeMessage setContent将设置整个消息的内容
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.