我試圖使用javamail從webapp發送一封電子郵件,並且郵件沒有發送正文和附件。我試着調試它,我看不出有什麼問題。 我使用tomee + 1.7和javamail 1.4.7。javamail不發送郵件內容
這裏是我的代碼:
// Msg body
session.setDebug(true);
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("Attached are your query results");
messageBodyPart.addHeader("Content-Type", "text/html; charset=windows-1255");
messageBodyPart.addHeader("Content-Transfer-Encoding", "base64");
// attachment
LOG.info("Building attachment from file " + file.getName());
MimeBodyPart attachmentPart = new MimeBodyPart();
attachmentPart.attachFile(file);
attachmentPart.setFileName(file.getName());
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
multipart.addBodyPart(attachmentPart);
// Send message
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Query report...");
message.setContent(multipart);
Transport.send(message);
LOG.info("Sent message successfully ...");
我得到的消息:
From: [email protected]
To: [email protected]
Message-ID: <[email protected]>
Subject: Query report...
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_0_1099874708.1409738093124"
「我嘗試過調試它,我看不到有什麼問題」;您可以發佈javamail的調試輸出,因爲您設置了'session.setDebug(true);' – Seismoid 2014-09-02 15:13:39
您是否在任何地方看到錯誤消息? – 2014-09-02 15:19:36
任何地方都沒有錯誤消息..我實際上收到一條空消息 – style 2014-09-03 09:42:22