Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void sendMail(EmailConfiguration a_emailConfiguration) {
- Properties props = new Properties();
- final String userName = environment.getProperty("mail.username");
- final String password = environment.getProperty("mail.password");
- String protocol = environment.getProperty("mail.transport.protocol", "smtp");
- String host = environment.getProperty("mail.smtp.host");
- String port = environment.getProperty("mail.smtp.port");
- String auth = environment.getProperty("mail.smtp.auth");
- String starttls = environment.getProperty("mail.smtp.starttls.enable");
- String socketPort = environment.getProperty("mail.smtp.socketFactory.port");
- String socketClass = environment.getProperty("mail.smtp.socketFactory.class");
- props.put("mail.smtp.host", host);
- props.put("mail.smtp.port", port);
- if (StringUtils.isNotEmpty(socketPort)) {
- props.put("mail.smtp.socketFactory.port", socketPort);
- }
- if (StringUtils.isNotEmpty(socketClass)) {
- props.put("mail.smtp.socketFactory.class", socketClass);
- }
- if (StringUtils.isNotEmpty(auth)) {
- props.put("mail.smtp.auth", auth);
- }
- if (StringUtils.isNotEmpty(starttls)) {
- props.put("mail.smtp.starttls.enable", starttls);
- }
- Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(userName, password);
- }
- });
- try {
- Transport transport = session.getTransport(protocol);
- MimeMessage message = new MimeMessage(session);
- message.setFrom(new InternetAddress(a_emailConfiguration.getFromEmail(), a_emailConfiguration
- .getFromLabel()));
- message.setRecipients(Message.RecipientType.TO,
- a_emailConfiguration.getRecipients(Message.RecipientType.TO));
- message.setSubject(a_emailConfiguration.getSubject(), "UTF-8");
- message.setHeader("Content-Type", EMAIL_CONTENT_ENCODING);
- if (StringUtils.isNotEmpty(a_emailConfiguration.getTemplateFileName())
- && StringUtils.isNotEmpty(a_emailConfiguration.getTemplateBasepath())) {
- message.setContent(mailTemplate.getTemplateContent(a_emailConfiguration.getTemplateFileName(),
- a_emailConfiguration.getTemplateParameters(), a_emailConfiguration.getTemplateBasepath()),
- EMAIL_CONTENT_ENCODING);
- } else {
- message.setContent(a_emailConfiguration.getContent(), EMAIL_CONTENT_ENCODING);
- }
- if (mailSender != null) {
- transport.connect(host, Integer.valueOf(port), userName, password);
- transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
- transport.close();
- }
- } catch (Exception e) {
- LOG.error("Send mail error", e);
- }
- }
- mail.transport.protocol=smtps
- mail.smtp.host=in-v3.mailjet.com
- mail.smtp.port=465
- mail.smtp.auth=true
- mail.smtp.starttls.enable=
- mail.username=bf52e8fed8bfb593ed2ebc060252cbad
- mail.password=24a7ef2492afba66d7ee45d779a328cf
- mail.smtp.socketFactory.port=465
- mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
- mail.adress.from.name=Contact MyPrevention
- mail.adress.from=contact@myprevention.fr
- mail.account.sendEmailConfirmation.subject=Changement de votre adresse email MyPrevention
- mail.account.sendInvitation.subject=Invitation MyPrevention
- mail.account.activation.subject= Validez votre compte
- mail.account.reinitialization.subject= R\u00E9initialisation du mot de passe
- mail.account.password.reinitialized = Votre mot de passe a bien \u00E9t\u00E9 modifi\u00E9
- mail.support.adress.from=contact@myprevention.fr
- mail.support.adress.from.name=Support My Prevention
- mail.support.adress.to=santech@yopmail.com
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement