Advertisement
Guest User

Send mails with Java in ARIS

a guest
Oct 25th, 2019
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Mail( ) {
  2.     /**
  3.     * SMTP server
  4.     */
  5.     var m_server = "SMTP_SERVER_ADDRESS_GOES_HERE"; //Insert name of smtp server here
  6.     /**
  7.     * send an email with an attachment to a list of recipients
  8.     *
  9.     * @param sReply - a email address
  10.     * @param arrRecepients - array of recipients
  11.     * @param sSubject - the email subject
  12.     * @param sContent - the email body content
  13.     * @param sAttachmentFileName - filename and path to the attachment
  14.     *
  15.     * @return void
  16.     */
  17.     this.send = function(sContent) {
  18.        
  19.         /**if(sContent.length == 0){
  20.             return false;
  21.         }**/
  22.        
  23.         var i = 0;
  24.         var props = new java.util.Properties();
  25.         props.setProperty("mail.smtp.auth", "false/true"); //make this string variable either "true" or "false", depending on if your mail server needs smtp authentificiation
  26.         props.setProperty("mail.smtp.host", m_server);
  27.        
  28.         var instSession = Packages.javax.mail.Session.getInstance(props, null);
  29.         var smtpTransport = instSession.getTransport("smtp");
  30.  
  31.         smtpTransport.connect();
  32.      
  33.         var adrReply = new Packages.javax.mail.internet.InternetAddress("REPLY_E_MAIL_ADDRESS_GOES_HERE"); //Insert e-mail address here, to which receivers of the message will reply when they click on reply (not necessarily the sender of the original message)                
  34.          
  35.         var msg = new Packages.javax.mail.internet.MimeMessage(instSession);
  36.         msg.setFrom(adrReply);
  37.          
  38.         msg.setSentDate(new Date());
  39.          
  40.         msg.setReplyTo(new Array(adrReply));
  41.         msg.setRecipients(Packages.javax.mail.internet.MimeMessage.RecipientType.TO, [new Packages.javax.mail.internet.InternetAddress("RECIPIENT_E_MAIL_ADDRESS_GOES_HERE")]); //this array should contain objects of the Packages.javax.mail.internet.InternetAddress class, which represent the recipients of the mail
  42.          
  43.         // "Subject": Subject of the mail    
  44.         msg.setSubject("SUBJECT_GOES_HERE", "UTF-8"); //configure the e-mail subject here
  45.        
  46.          
  47.         messagePart = new Packages.javax.mail.internet.MimeBodyPart(); //Take a look at the javax.internet Java package there are lots of components which you can use to compose your email body
  48.         messagePart.setContent(sContent, "text/html");
  49.        
  50.         multipart = new Packages.javax.mail.internet.MimeMultipart();
  51.         multipart.addBodyPart(messagePart);
  52.  
  53.         msg.setContent(multipart);
  54.  
  55.         smtpTransport.sendMessage(msg, [new Packages.javax.mail.internet.InternetAddress("SENDER_E_MAIL_ADDRESS_GOES_HERE")]); // Insert the e-mail address that will be used to send the message here
  56.  
  57.         smtpTransport.close();    
  58.     }
  59.    
  60.      
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement