javamail发送邮件附件重复问题
通过javamail发送邮件中,添加一个附件,结果收到的一封邮件中包含2个相同的附件。
代码如下:
MimeMessage message = new MimeMessage(session);
message.setSubject(mail_subject);//设置邮件主题
message.setText(mail_content);//设置邮件内容
message.setSentDate(new Date());//设置邮件发送时期
Address address = new InternetAddress(mail_from,mail_from);
message.setFrom(address);//设置邮件发送者的地址
message.addRecipients(Message.RecipientType.TO,addressesL);
if(StringUtils.isNotBlank(mailtocc)){
for(int x=0;x<Mailtocc.length;x++){
addressesM[x] = new InternetAddress(Mailtocc[x]);
}
message.addRecipients(Message.RecipientType.CC, addressesM);
}
MimeBodyPart messageBodyPart =new MimeBodyPart();
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
File attachment;
attachment= new File(filepath);
DataSource fileDataSource=new FileDataSource(attachment);
messageBodyPart.setDataHandler(new DataHandler(fileDataSource));
messageBodyPart.setFileName(attachment.getName());
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
求大侠帮助
------解决方案--------------------
通过javamail发送邮件中,添加一个附件,结果收到的一封邮件中包含2个相同的附件。
代码如下:
MimeMessage message = new MimeMessage(session);
message.setSubject(mail_subject);//设置邮件主题
message.setText(mail_content);//设置邮件内容
message.setSentDate(new Date());//设置邮件发送时期
Address address = new InternetAddress(mail_from,mail_from);
message.setFrom(address);//设置邮件发送者的地址
message.addRecipients(Message.RecipientType.TO,addressesL);
if(StringUtils.isNotBlank(mailtocc)){
for(int x=0;x<Mailtocc.length;x++){
addressesM[x] = new InternetAddress(Mailtocc[x]);
}
message.addRecipients(Message.RecipientType.CC, addressesM);
}
MimeBodyPart messageBodyPart =new MimeBodyPart();
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
File attachment;
attachment= new File(filepath);
DataSource fileDataSource=new FileDataSource(attachment);
messageBodyPart.setDataHandler(new DataHandler(fileDataSource));
messageBodyPart.setFileName(attachment.getName());
multipart.addBodyPart(messageBodyPart); message.setContent(multipart);