Jump to content
Sign in to follow this  
Ocean West

Script Master Multiple Email Parameters

Recommended Posts

I am trying to figure out how to extend SM SendEmail to also contain CC & BCC options?

Share this post


Link to post
Share on other sites

Ok I have figured out how to get the CC & BCC options working the next question is dealing with multiples. Multiple TO's CC's BCC's and ATTACHMENTS... any ideas?

Share this post


Link to post
Share on other sites

Process...

First I have a CF that creates:

SetEmailVariable ( from ; to ; cc ; bcc ; subject ; body ; html ; attach )


Let ( [



//USED IN GROOVY CODE

$sm_cc = cc ;

$sm_bcc = bcc ;

$sm_html = html;

$sm_attach = attach 



];



// Headers

SMSetVariable( "from" ; Case ( IsEmpty (  from  ); Case( IsEmpty( $$Email ) ;  "ERROR" ; $$Email ) ; from ) ) &

SMSetVariable( "to" ; to ) &



SMSetVariable ( "cc" ; cc )   &

SMSetVariable ( "bcc" ; bcc )   &



//Subject

SMSetVariable( "subject" ; subject ) &



// Body

SMSetVariable( Case( $sm_html ; "htmlBody" ; "body")  ; body ) &



//Attach

SMSetVariable( "attachmentPath" ; attach ) &



//SMTP

SMSetVariable( "smtpHost" ; "mail.domain.com" )



)







Then my groovy code is:





"import javax.mail.*;¶

import javax.mail.internet.*;¶

¶

Properties props = new Properties();¶

props.setProperty("mail.smtp.host", smtpHost);¶

MimeMessage msg = new MimeMessage(Session.getDefaultInstance(props));¶



msg.setSubject(subject);¶

msg.setFrom(new InternetAddress(from));¶

msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));¶" &



Case ( $sm_cc  ; "msg.setRecipient(Message.RecipientType.CC, new InternetAddress(cc));¶"  ) &

Case ( $sm_bcc  ; "msg.setRecipient(Message.RecipientType.BCC, new InternetAddress(bcc));¶" ) &





Case (  $sm_attach ; 

"Multipart content = new MimeMultipart();¶

// first the message body¶

MimeBodyPart bodyPart = new MimeBodyPart();¶

bodyPart.setText(body);¶

content.addBodyPart(bodyPart);¶

// then the attachment¶

MimeBodyPart attachmentPart = new MimeBodyPart();¶

attachmentPart.attachFile(attachmentPath);¶

content.addBodyPart(attachmentPart);¶

msg.setContent(content);¶ " ; 



Case ( $sm_html ; "msg.setContent( htmlBody, "text/html");¶" ; "msg.setText(body);¶" ) ) &



"Transport.send(msg);¶

return true;"

If there is a cleaner method to this - I am hoping to make this most generic so that it can be used in any different circumstance w/ or w/o CC / BCC / ATTACHMENTS and if the body is HTML

Your suggestions are welcome :

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.