May 16, 200916 yr I am trying to figure out how to extend SM SendEmail to also contain CC & BCC options?
May 20, 200916 yr Author 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?
May 20, 200916 yr Author 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 :
Create an account or sign in to comment