Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Mail( ) {
- /**
- * SMTP server
- */
- var m_server = "SMTP_SERVER_ADDRESS_GOES_HERE"; //Insert name of smtp server here
- /**
- * send an email with an attachment to a list of recipients
- *
- * @param sReply - a email address
- * @param arrRecepients - array of recipients
- * @param sSubject - the email subject
- * @param sContent - the email body content
- * @param sAttachmentFileName - filename and path to the attachment
- *
- * @return void
- */
- this.send = function(sContent) {
- /**if(sContent.length == 0){
- return false;
- }**/
- var i = 0;
- var props = new java.util.Properties();
- props.setProperty("mail.smtp.auth", "false/true"); //make this string variable either "true" or "false", depending on if your mail server needs smtp authentificiation
- props.setProperty("mail.smtp.host", m_server);
- var instSession = Packages.javax.mail.Session.getInstance(props, null);
- var smtpTransport = instSession.getTransport("smtp");
- smtpTransport.connect();
- 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)
- var msg = new Packages.javax.mail.internet.MimeMessage(instSession);
- msg.setFrom(adrReply);
- msg.setSentDate(new Date());
- msg.setReplyTo(new Array(adrReply));
- 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
- // "Subject": Subject of the mail
- msg.setSubject("SUBJECT_GOES_HERE", "UTF-8"); //configure the e-mail subject here
- 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
- messagePart.setContent(sContent, "text/html");
- multipart = new Packages.javax.mail.internet.MimeMultipart();
- multipart.addBodyPart(messagePart);
- msg.setContent(multipart);
- 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
- smtpTransport.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement