Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. <camel:camelContext xmlns="http://camel.apache.org/schema/spring">
  2.  
  3. <camel:route id="gmailRoute">
  4. <camel:from uri="direct://gmail" />
  5. <camel:to
  6. uri="smtp://p****is@gmail.com?host=smtp.gmail.com&port=587&from=p****is@gmail.comi&password=gl******" />
  7. </camel:route>
  8.  
  9. log.info("Initializing Email Service");
  10.  
  11. Properties props = new Properties();
  12. props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
  13. props.put("mail.smtp.auth", "true");
  14. props.put("mail.smtp.starttls.enable", "true");
  15. props.put("mail.smtp.host", "smtp.googlemail.com");
  16. props.put("mail.smtp.port", "587");
  17. Authenticator auth = null;
  18. props.put("mail.smtp.auth", "true");
  19. auth = new Authenticator() {
  20. protected PasswordAuthentication getPasswordAuthentication() {
  21. return new PasswordAuthentication("******akis@gmail.com", "gl*****s");
  22. }
  23. };
  24. Session t = Session.getInstance(props, auth);
  25.  
  26. template = camelContext.createProducerTemplate();
  27.  
  28. @Override
  29. public void sendEmail(String from, String[] to, String[] cc, String[] bcc, String subject, String body)
  30. {
  31. String endpoint = "direct://gmail";
  32. String toString = null;
  33. String ccString = null;
  34. String bccString = null;
  35. Map<String, Object> headers = null;
  36.  
  37. toString = convertStringArrayToCSV(to);
  38. ccString = convertStringArrayToCSV(cc);
  39. bccString = convertStringArrayToCSV(bcc);
  40.  
  41. headers = new HashMap<String, Object>();
  42. headers.put("Subject", subject);
  43. if (toString != null)
  44. {
  45. headers.put("To", toString);
  46. }
  47.  
  48. if (ccString != null)
  49. {
  50. headers.put("CC", ccString);
  51. }
  52.  
  53. if (bccString != null)
  54. {
  55. headers.put("BCC", bccString);
  56. }
  57.  
  58. template.sendBodyAndHeaders(endpoint, body, headers);
  59.  
  60. }
  61.  
  62. <camel:camelContext xmlns="http://camel.apache.org/schema/spring">
  63. <camel:route id="gmailRoute">
  64. <camel:from uri="direct://gmail" />
  65. <camel:to uri="smtps://p****is@gmail.com?host=smtp.gmail.com&port=587&from=p****is@gmail.comi&password=gl******" />
  66. </camel:route>
  67. </camel:camelContext>
  68.  
  69. smtp://smtp.gmail.com?port=587&username=USERNAME@gmail.com&password=PASSOWRD&mail.smtp.auth=true&mail.smtp.starttls.enable=true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement