Hallo zusammen,
ich habe ne Klasse mit 2 Methoden. Eine sendet Mails mit Anhang, die andere Ohne. Wenn ich jedoch eine Ohne sende, ist bei Outlook & Co. trotzdem ne Büroklammer zu sehen, aber kein Anhang. Was hab ich hier falsch gemacht? Möchte, dass die Büroklammer wegkommt...ist ja auch kein Anhang dran.
Vermute, es liegt hier ran, aber was genau ist da falsch
ich habe ne Klasse mit 2 Methoden. Eine sendet Mails mit Anhang, die andere Ohne. Wenn ich jedoch eine Ohne sende, ist bei Outlook & Co. trotzdem ne Büroklammer zu sehen, aber kein Anhang. Was hab ich hier falsch gemacht? Möchte, dass die Büroklammer wegkommt...ist ja auch kein Anhang dran.
Java:
public static void sendMail(String recipients, String subject, String message) throws MessagingException,
AuthenticationFailedException {
// sets SMTP server properties
Properties properties = new Properties();
properties.put("mail.smtp.host", SMTP_HOST_NAME);
properties.put("mail.smtp.port", SMTP_PORT);
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "false");
properties.put("mail.user", SMTP_AUTH_USER);
properties.put("mail.password", SMTP_AUTH_PWD);
// creates a new session with an authenticator
Authenticator auth = new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(SMTP_AUTH_USER, SMTP_AUTH_PWD);
}
};
Session session = Session.getInstance(properties, auth);
// creates a new e-mail message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(SMPT_SENDER_MAIL));
InternetAddress[] toAddresses = {new InternetAddress(recipients)};
msg.setRecipients(Message.RecipientType.TO, toAddresses);
msg.setSubject(subject);
msg.setSentDate(new Date());
// creates message part
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(message, "text/html");
// creates multi-part
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// sets the multi-part as e-mail's content
msg.setContent(multipart);
// sends the e-mail
Transport.send(msg);
}
Vermute, es liegt hier ran, aber was genau ist da falsch
Java:
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(message, "text/html");