Ocean West Posted May 16, 2009 Posted May 16, 2009 I am trying to figure out how to extend SM SendEmail to also contain CC & BCC options?
Ocean West Posted May 20, 2009 Author Posted May 20, 2009 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?
Ocean West Posted May 20, 2009 Author Posted May 20, 2009 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 :
Recommended Posts
This topic is 6054 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 accountSign in
Already have an account? Sign in here.
Sign In Now