Last active
October 1, 2021 13:43
-
-
Save GaetanoPiazzolla/e54f88dd415ff639f46c6d9c847a1152 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Service | |
public class MailService implements MailServiceI { | |
@Value("${smtp.host}") | |
private String host; | |
@Value("${smtp.auth}") | |
private String auth; | |
@Value("${smtp.port}") | |
private String port; | |
@Value("${smtp.username}") | |
private String username; | |
@Value("${smtp.email-from}") | |
private String fromMail; | |
@Value("${smtp.email-from-name}") | |
private String fromName; | |
@Value("${smtp.password}") | |
private String password; | |
@Override | |
public void sendNewMail(String email, String mailMessage, String subject) throws MailNotSentException { | |
Properties props = new Properties(); | |
props.put("mail.smtp.auth", auth); | |
props.put("mail.smtp.host", host); | |
props.put("mail.smtp.port", port); | |
Session session = Session.getInstance(props); | |
Message message = new MimeMessage(session); | |
message.setFrom(new InternetAddress(fromMail, fromName)); | |
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email)); | |
message.setSubject(subject); | |
message.setContent(mailMessage, "text/html; charset=utf-8"); | |
Transport.send(message, username, password); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
related to medium article https://medium.com/nerd-for-tech/using-jboss-credential-store-in-a-spring-application-4bacfd2d9e96