Advertisement
Guest User

Untitled

a guest
Mar 25th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 KB | None | 0 0
  1. public void sendMail(EmailConfiguration a_emailConfiguration) {
  2. Properties props = new Properties();
  3. final String userName = environment.getProperty("mail.username");
  4. final String password = environment.getProperty("mail.password");
  5.  
  6. String protocol = environment.getProperty("mail.transport.protocol", "smtp");
  7. String host = environment.getProperty("mail.smtp.host");
  8. String port = environment.getProperty("mail.smtp.port");
  9.  
  10. String auth = environment.getProperty("mail.smtp.auth");
  11. String starttls = environment.getProperty("mail.smtp.starttls.enable");
  12.  
  13. String socketPort = environment.getProperty("mail.smtp.socketFactory.port");
  14. String socketClass = environment.getProperty("mail.smtp.socketFactory.class");
  15.  
  16. props.put("mail.smtp.host", host);
  17. props.put("mail.smtp.port", port);
  18.  
  19. if (StringUtils.isNotEmpty(socketPort)) {
  20. props.put("mail.smtp.socketFactory.port", socketPort);
  21. }
  22. if (StringUtils.isNotEmpty(socketClass)) {
  23. props.put("mail.smtp.socketFactory.class", socketClass);
  24. }
  25. if (StringUtils.isNotEmpty(auth)) {
  26. props.put("mail.smtp.auth", auth);
  27. }
  28. if (StringUtils.isNotEmpty(starttls)) {
  29. props.put("mail.smtp.starttls.enable", starttls);
  30. }
  31.  
  32. Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
  33. protected PasswordAuthentication getPasswordAuthentication() {
  34. return new PasswordAuthentication(userName, password);
  35. }
  36. });
  37. try {
  38. Transport transport = session.getTransport(protocol);
  39. MimeMessage message = new MimeMessage(session);
  40. message.setFrom(new InternetAddress(a_emailConfiguration.getFromEmail(), a_emailConfiguration
  41. .getFromLabel()));
  42. message.setRecipients(Message.RecipientType.TO,
  43. a_emailConfiguration.getRecipients(Message.RecipientType.TO));
  44. message.setSubject(a_emailConfiguration.getSubject(), "UTF-8");
  45.  
  46. message.setHeader("Content-Type", EMAIL_CONTENT_ENCODING);
  47. if (StringUtils.isNotEmpty(a_emailConfiguration.getTemplateFileName())
  48. && StringUtils.isNotEmpty(a_emailConfiguration.getTemplateBasepath())) {
  49. message.setContent(mailTemplate.getTemplateContent(a_emailConfiguration.getTemplateFileName(),
  50. a_emailConfiguration.getTemplateParameters(), a_emailConfiguration.getTemplateBasepath()),
  51. EMAIL_CONTENT_ENCODING);
  52. } else {
  53. message.setContent(a_emailConfiguration.getContent(), EMAIL_CONTENT_ENCODING);
  54. }
  55. if (mailSender != null) {
  56. transport.connect(host, Integer.valueOf(port), userName, password);
  57. transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
  58. transport.close();
  59. }
  60. } catch (Exception e) {
  61. LOG.error("Send mail error", e);
  62. }
  63.  
  64. }
  65.  
  66.  
  67. mail.transport.protocol=smtps
  68. mail.smtp.host=in-v3.mailjet.com
  69. mail.smtp.port=465
  70. mail.smtp.auth=true
  71. mail.smtp.starttls.enable=
  72. mail.username=bf52e8fed8bfb593ed2ebc060252cbad
  73. mail.password=24a7ef2492afba66d7ee45d779a328cf
  74. mail.smtp.socketFactory.port=465
  75. mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
  76. mail.adress.from.name=Contact MyPrevention
  77. mail.adress.from=contact@myprevention.fr
  78. mail.account.sendEmailConfirmation.subject=Changement de votre adresse email MyPrevention
  79. mail.account.sendInvitation.subject=Invitation MyPrevention
  80. mail.account.activation.subject= Validez votre compte
  81. mail.account.reinitialization.subject= R\u00E9initialisation du mot de passe
  82. mail.account.password.reinitialized = Votre mot de passe a bien \u00E9t\u00E9 modifi\u00E9
  83. mail.support.adress.from=contact@myprevention.fr
  84. mail.support.adress.from.name=Support My Prevention
  85. mail.support.adress.to=santech@yopmail.com
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement