Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. // Helper function for converting array to coma separated list
  2. function convertToComaSeparatedList (arrayList) {
  3.  
  4. if ( arrayList == null || arrayList.length == 0) {
  5. return null
  6. }
  7.  
  8. var outStr = "";
  9. for (var i=0; i < arrayList.length; i++) {
  10. outStr += arrayList[i] + ",";
  11. }
  12. if (outStr.length > 0){
  13. outStr = outStr.substring(0, (outStr.length - 1));
  14. }
  15. return outStr;
  16. }
  17.  
  18. var message = new EmailMessage();
  19.  
  20. // Override default settings if and only if input parameter is set
  21. if ( smtpHost != null && smtpHost.length > 0 ){
  22. message.smtpHost = smtpHost;
  23. }
  24. if ( smtpPort != null && smtpPort > 0 ){
  25. message.smtpPort = smtpPort;
  26. }
  27. if ( username !=null && username.length > 0){
  28. message.username = username;
  29. }
  30. if ( password != null && password.length > 0){
  31. message.password = password;
  32. }
  33. if ( fromName != null && fromName.length > 0){
  34. message.fromName = fromName;
  35. }
  36. if ( fromAddress != null && fromAddress.length > 0){
  37. message.fromAddress = fromAddress;
  38. }
  39.  
  40. // Build Address Lists
  41. message.toAddress = convertToComaSeparatedList(toAddressList);
  42. message.ccAddress = convertToComaSeparatedList(ccList);
  43. message.bccAddress = convertToComaSeparatedList(bccList);
  44.  
  45. // Set subject
  46. message.subject = subject;
  47.  
  48. // Add text part of the email
  49. message.addMimePart(content,"text/html; charset=UTF-8");
  50.  
  51. // Add attachment
  52. message.addMimePart(attachment, attachment.mimeType);
  53.  
  54. // Send message
  55. message.sendMessage();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement