diff options
| author | AlisaLinUwU <alisalinuwu@gmail.com> | 2025-01-26 11:41:45 +0500 | 
|---|---|---|
| committer | AlisaLinUwU <alisalinuwu@gmail.com> | 2025-01-26 11:41:45 +0500 | 
| commit | 93fe6a825baa3c5141fb220256b2c0b1fc3da273 (patch) | |
| tree | b9cca4a0b970e8ee53a6465c1d2a572fb6dfb825 /src/main/java/com/mavlushechka/notary/util | |
Initializemain
Diffstat (limited to 'src/main/java/com/mavlushechka/notary/util')
| -rw-r--r-- | src/main/java/com/mavlushechka/notary/util/EmailSender.java | 46 | 
1 files changed, 46 insertions, 0 deletions
| diff --git a/src/main/java/com/mavlushechka/notary/util/EmailSender.java b/src/main/java/com/mavlushechka/notary/util/EmailSender.java new file mode 100644 index 0000000..ffdd62a --- /dev/null +++ b/src/main/java/com/mavlushechka/notary/util/EmailSender.java @@ -0,0 +1,46 @@ +package com.mavlushechka.notary.util; + +import javax.mail.*; +import javax.mail.internet.*; +import java.util.Properties; + +public class EmailSender { + +    private final static Session SESSION; + +    static { +        Properties properties = new Properties(); +        properties.put("mail.smtp.auth", true); +        properties.put("mail.smtp.starttls.enable", true); +        properties.put("mail.smtp.host", "smtp.mailtrap.io"); +        properties.put("mail.smtp.port", "2525"); +        properties.put("mail.smtp.ssl.trust", "smtp.mailtrap.io"); +        properties.put("mail.smtp.ssl.protocols", "TLSv1.2"); + +        SESSION = Session.getInstance(properties, new Authenticator() { +            @Override +            protected PasswordAuthentication getPasswordAuthentication() { +                return new PasswordAuthentication("4df6840637b3c8", "829aff4fc98967"); +            } +        }); +    } + + +    public static void send(String from, String to, String subject, String messageText) throws MessagingException { +        Message message = new MimeMessage(SESSION); +        message.setFrom(new InternetAddress(from)); +        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); +        message.setSubject(subject); + +        MimeBodyPart mimeBodyPart = new MimeBodyPart(); +        mimeBodyPart.setContent(messageText, "text/html; charset=utf-8"); + +        Multipart multipart = new MimeMultipart(); +        multipart.addBodyPart(mimeBodyPart); + +        message.setContent(multipart); + +        Transport.send(message); +    } + +} |