#MimeMailMessage - message not delivery to e-mail
1 messages · Page 1 of 1 (latest)
<@&1004656351647117403> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
Properties properties = new Properties();
properties.put("mail.smtp.host", "smtp.gmail.com");
String username = "hidden";
String password = "hidden";
properties.put("mail.smtp.port", 587);
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.user", username);
properties.put("mail.password", password);
Authenticator auth = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
};
Session session = Session.getInstance(properties, auth);
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent("I have some attachments for you", "text/html");
Multipart multipart = new MimeMultipart();
MimeBodyPart attachPart = new MimeBodyPart();
try {
attachPart.attachFile("C:\\orion\\xx.pdf");
} catch (IOException ex) {
ex.printStackTrace();
}
multipart.addBodyPart(attachPart);
// creates a new e-mail message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("hidden"));
InternetAddress[] toAddresses = { new InternetAddress(toEmail) };
msg.setRecipients(Message.RecipientType.TO, toAddresses);
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setContent(multipart);
// sends the e-mail
Transport.send(msg);
}```
Detected code, here are some useful tools: