Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 5677 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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

Posted

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?

Posted

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 :

This topic is 5677 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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