我正在尝试使用Java发送带有附件的电子邮件.
当我发送没有附件的电子邮件时,我收到了电子邮件,但是当我添加附件时,我没有收到任何内容,我也没有收到任何错误消息.
这是我正在使用的代码:
public void send () throws AddressException, MessagingException{
//system properties
Properties props = new Properties();
props.put("mail.smtp.localhost", "localhost");
props.put("mail.smtp.host",Configurations.getInstance().email_serverIp);
/*
* create some properties and get the default Session
*/
session = Session.getDefaultInstance(props, null);
//session
Session session = Session.getInstance(props, null);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("zouhaier.mhamdi@gmail.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("zouhaier.mhamdi@gmail.com"));
message.setSubject("Testing Subject");
message.setText("PFA");
MimeBodyPart messageBodyPart = new MimeBodyPart();
Multipart multipart = new MimeMultipart();
generateCsvFile("/tmp/test.csv");
messageBodyPart = new MimeBodyPart();
String file = "/tmp/test.csv";
String fileName = "test.csv";
DataSource source = new …
Run Code Online (Sandbox Code Playgroud)