我想知道如何通过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 = …Run Code Online (Sandbox Code Playgroud) java-ee ×1