Spring Boot - E -Mail über SMTP Jakarta sendenJava

Java-Forum
Anonymous
 Spring Boot - E -Mail über SMTP Jakarta senden

Post by Anonymous »

Ich habe diese Klasse, die E -Mails mit Localhost von demselben Server aussendet, aber beim Senden von E -Mails von einer anderen IP und beim Festlegen des Hosts wie folgt: < /p>

Code: Select all

@Service
@Slf4j
@Transactional(readOnly = true)
public class MailMessageService extends SimpleMailMessage {

static Properties prop = new Properties();

public MailMessageService() {
super();
}

public void sendMessage(String subject, String body, String mailTo, String pathToFile) throws MessagingException, IOException {

log.info("Sending email to: *{}* ", mailTo);

Session session = Session.getInstance(prop, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("info", "oT2ct2UUii87");
}

});

Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]"));

message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(mailTo));
message.setSubject(subject);

MimeBodyPart mimeBodyPart = new MimeBodyPart();
mimeBodyPart.setContent(body, "text/html; charset=utf-8");

Multipart multipart = new MimeMultipart();
multipart.addBodyPart(mimeBodyPart);

log.info("pathToFile: *{}* ", pathToFile);

if (pathToFile != null) {
MimeBodyPart attachment = new MimeBodyPart();
attachment.attachFile(pathToFile);
multipart.addBodyPart(attachment);
}

log.info("Setting content");

message.setContent(multipart);

log.info("Sending message {} ", message);

Transport.send(message);

}

public void sendMessage(String subject, String body, String mailTo) throws MessagingException, IOException {

sendMessage(subject, body, mailTo, null);

}

@PostConstruct
public void initProperties() {
prop.put("mail.smtp.auth", true);
prop.put("mail.smtp.starttls.enable", "true");
prop.put("mail.smtp.host", "172.105.90.58");
prop.put("mail.smtp.port", "25");
prop.put("mail.smtp.ssl.trust", "172.105.90.58");
}
}
< /code>
Ich habe diese Fehler: < /p>
jakarta.mail.MessagingException: Could not convert socket to TLS
at org.eclipse.angus.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:2173)
at org.eclipse.angus.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:741)
at jakarta.mail.Service.connect(Service.java:367)
at jakarta.mail.Service.connect(Service.java:225)
at jakarta.mail.Service.connect(Service.java:174)
at jakarta.mail.Transport.send0(Transport.java:232)
at jakarta.mail.Transport.send(Transport.java:102)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post