1
我想知道如何通過Java程序發送圖像到郵件。我可以發送文本和圖像,但它顯示爲附加文件.. 我想這應是我的文字的過去...... 下面是我用通過Java程序發送圖像到郵件而不附加?
// Create new message with mail session.
Message message = new MimeMessage(session);
// Create multipart message.
MimeMultipart multipart = new MimeMultipart();
// Create bodypart.
BodyPart bodyPart = new MimeBodyPart();
// Create the HTML with link to image CID.
// Prefix the link with "cid:".
String str = "<html><h1>Hello</h1>" +
"<img src=\"cid:image_cid\"></html>";
// Set the MIME-type to HTML.
bodyPart.setContent(str, "text/html");
// Add the HTML bodypart to the multipart.
multipart.addBodyPart(bodyPart);
// Create another bodypart to include the image attachment.
bodyPart = new MimeBodyPart();
// Read image from file system.
DataSource ds = new FileDataSource("C:\\images\\image.png");
bodyPart.setDataHandler(new DataHandler(ds));
// Set the content-ID of the image attachment.
// Enclose the image CID with the lesser and greater signs.
bodyPart.setHeader("Content-ID", "<image_cid>");
// Add image attachment to multipart.
multipart.addBodyPart(bodyPart);
// Add multipart content to message.
message.setContent(multipart);
// Now set the header and send the email.
...
,請告訴我,如果任何人知道。 。
感謝進階