Код: Выделить всё
[img]cid:logo[/img]
Код: Выделить всё
public void sendMailWithInlineImage(String recipientEmail,
String contentHtml,
String subject,
byte[] imageBytes,
String contentId,
String contentType,
boolean onCreate)
throws MessagingException {
if (session == null) {
refreshSession();
}
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(email));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipientEmail));
message.setSubject(subject, StandardCharsets.UTF_8.name());
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(contentHtml, "text/html; charset=UTF-8");
ByteArrayDataSource ds = new ByteArrayDataSource(imageBytes, contentType);
ds.setName("logo.png");
MimeBodyPart imagePart = new MimeBodyPart();
imagePart.setDataHandler(new DataHandler(ds));
imagePart.setContentID("");
imagePart.setDisposition(MimeBodyPart.INLINE);
imagePart.setFileName("logo.png");
imagePart.setHeader("Content-Type", contentType + "; name=logo.png");
MimeMultipart multipart = new MimeMultipart("related");
multipart.addBodyPart(htmlPart);
multipart.addBodyPart(imagePart);
message.setContent(multipart);
Transport.send(message);
} catch (MessagingException ex) {
if (onCreate) {
refreshSession();
sendMailWithInlineImage(recipientEmail, contentHtml, subject,
imageBytes, contentId, contentType, false);
} else {
throw ex;
}
}
}
Код: Выделить всё
public void sendActivation(User user) {
log.info("--START sendActivation");
try {
String html = Files.toString(activeTemplate.getFile(), Charsets.UTF_8);
html = html.replace("https://google.com", fontendUrl + "/activate/" + user.getUuid());
byte[] logoBytes = Files.toByteArray(logoResource.getFile());
emailConfiguration.sendMailWithInlineImage(
user.getEmail(),
html,
"Aktywacja konta",
logoBytes,
"logo",
"image/png",
true
);
} catch (IOException | MessagingException e) {
log.error("Błąd wysyłania maila", e);
throw new RuntimeException(e);
}
log.info("--STOP sendActivation");
}
Я также имею это предупреждение в идее IntelliJ в файле .html: < /p>
ps. Я также пытался отобразить логотип с помощью хостинга Imgur и т. Д., Но результат был идентичным.
Подробнее здесь: https://stackoverflow.com/questions/796 ... e-on-gmail