我正在使用SpringFramework尝试使用zip附件的邮件。但是每次邮件都没有附件而且邮件也会以不正确的格式出现。请在下面找到收到的样本邮件
-----=_Part_0_26427166.1408022473482
Content-Type: multipart/related; boundary="----=_Part_1_7846309.1408022473566"
------=_Part_1_7846309.1408022473566
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Hi,
The attached spreadsheet contains a attachment
Please do not hesitate to contact us on the details below with any queries.
Many thanks for your assistance.
------=_Part_1_7846309.1408022473566--
------=_Part_0_26427166.1408022473482
Content-Type: application/zip; name=Details.zip
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=Details.zip
81oAzlM+ZGz7u+8GiaN9S+kXWndHm82/62wMeRMcrP4yA64ihuMPk6YuvIpaFubSkjhgt9f6GMlK
nSLtW3zWKKdcMyO1WjAqgpobIAfRKoub5rd8kRhvsp28x9cblrN9CewpHTkJq4jVkKcRU1Cyz5K5
==
------=_Part_0_26427166.1408022473482--
答案 0 :(得分:0)
我使用此代码在我的应用程序中发送电子邮件:
private String from;
private JavaMailSender mailSender;
private VelocityEngine velocityEngine;
public void send(String to, String subject, String vt, String[] files, Map<String, Object> model) {
MimeMessage msg=mailSender.createMimeMessage();
try {
MimeMessageHelper helper = new MimeMessageHelper(msg, true, "UTF-8");
helper.setTo(to);
helper.setFrom(from);
helper.setText(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, vt, "UTF-8", model), true);
helper.setSubject(subject);
FileSystemResource file;
if(files!=null) {
//add attachments
for(String f : files ) {
file = new FileSystemResource(new File(f));
helper.addAttachment(file.getFilename(), file);
}
}
mailSender.send(msg);
} catch(MessagingException me) {
log.error("Cannot send email message");
}
}
因此,您可以与您的代码进行比较