Package com.ibm.sbt.services.client.email

Examples of com.ibm.sbt.services.client.email.MimeEmailException


     * @see com.ibm.sbt.services.client.email.MimeEmail#send()
     */
    @Override
    public void send() throws MimeEmailException {
        if(getTo().isEmpty() && getCC().isEmpty() && getBCC().isEmpty()) {
            throw new MimeEmailException("The email's to, cc, and bcc fields are empty.");
        }
        try {
          // Should use the log.nsf first!
            //Database db = DominoUtils.openDatabaseByName("log.nsf");
          Database db = ExtLibUtil.getCurrentDatabase();
          if(db==null) {
            // Should use the log application
            throw new MimeEmailException("Unbale to find an NSF to send the email message");
          }
      lotus.domino.Session session = db.getParent();
      Document doc = db.createDocument();

      doc.appendItemValue("Form", "Memo"); //$NON-NLS-1$

      doc.appendItemValue("Subject", getSubject()); //$NON-NLS-1$
      doc.appendItemValue("SendTo", getCommaSeparatedTo()); //$NON-NLS-1$
      doc.appendItemValue("CopyTo", getCommaSeparatedCC()); //$NON-NLS-1$
      doc.appendItemValue("BlindCopyTo", getCommaSeparatedTo()); //$NON-NLS-1$

      boolean convertMime = session.isConvertMime();
      session.setConvertMIME(false);
      try {
 
        MIMEEntity topRelated = doc.createMIMEEntity("Body"); //$NON-NLS-1$
 
        // Set up the multipart header
        MIMEHeader header = topRelated.createHeader("Content-Type"); //$NON-NLS-1$
 
        // EE needs to use multipart/alternative or the email clients will
        // turn the content into an attachment.
        header.setHeaderVal("multipart/related");
 
        MIMEEntity topAlternative = topRelated.createChildEntity();
 
        // Set up the multipart header
        header = topAlternative.createHeader("Content-Type");
 
        // EE needs to use multipart/alternative or the email clients will
        // turn the content into an attachment.
        header.setHeaderVal("multipart/alternative");
 
        try {
          for(MimePart part : getMimeParts()) {
            MIMEEntity mime = topAlternative.createChildEntity();
            try {
              lotus.domino.Stream stream = session.createStream();
              try {
                String mimeType = part.getMimeType();
                String content = part.getContent();
                stream.writeText(content);
                mime.setContentFromText(stream, mimeType, 0);
                if(StringUtil.equals(mimeType, "text/plain")) {
                  mime.encodeContent(MIMEEntity.ENC_QUOTED_PRINTABLE);
                } else {
                        mime.encodeContent(MIMEEntity.ENC_BASE64);
                }
              } finally {
                stream.close();
                stream.recycle();
              }
            } finally {
              mime.recycle();
            }
                }
 
         
 
  // USING JAVA MAIL       
  //              MimeMultipart mmp = new MimeMultipart("alternative");
  //              MimeBodyPart bodyPart;
  //              for(MimePart part : getMimeParts()) {
  //                  bodyPart = new MimeBodyPart();
  //                  bodyPart.setContent(part.getContent(), part.getMimeType());
  //                  Map<String, String> headers = part.getHeaders();
  //                  Set<String> keys = headers.keySet();
  //                  for(String key : keys) {
  //                      bodyPart.addHeader(key, headers.get(key));
  //                  }
  //                  mmp.addBodyPart(bodyPart);
  //              }
  //              msg.setContent(mmp);
         
          // format of email message in regards to various parts
          // multipart/related
          // multipart/alternative
          // plain text
          // embedded experience (json or xml)
          // html
 
  // USING NOTES API       
  //        Iterator<MimeBodyPartWrapper> keyItr = mimePartList.iterator();
  //
  //        MimeBodyPart mimePart;
  //        MimeBodyPartWrapper mimePartWrapper;
  //        MIMEEntity mime;
  //        lotus.domino.Stream stream;
  //        while (keyItr.hasNext()) {
  //          mimePartWrapper = keyItr.next();
  //          mimePart = mimePartWrapper.getMimeBodyPart();
  //          // mimePart.setHeader("Content-transfer-encoding",
  //          // encodingType);
  //          mime = topAlternative.createChildEntity();
  //          // header = mime.createHeader("Content-transfer-encoding");
  //          // header.setHeaderVal(encodingType);
  //          stream = session.createStream();
  //          stream.writeText((String) mimePart.getContent());
  //
  //          // mime.setContentFromText(stream,
  //          // mimePart.getContentType(), 0);
  //          // String cType="text/plain";
  //          if (TEXT_PLAIN.equalsIgnoreCase(mimePartWrapper.getContentType())) {
  ////            System.out.println("here plain text");
  //            mime.setContentFromText(stream, TEXT_PLAIN, 0);
  //            mime.encodeContent(MIMEEntity.ENC_QUOTED_PRINTABLE);
  //          } else if (EMBED_JSON.equalsIgnoreCase(mimePartWrapper.getContentType())) {
  ////            System.out.println("here ee json");
  //            mime.setContentFromText(stream, EMBED_JSON, 0);
  ////            System.out.println("ee json encoding: "
  ////                + mime.getEncoding()
  ////                + ", MIMEEntity.ENC_BASE64: "
  ////                + MIMEEntity.ENC_BASE64);
  //            mime.encodeContent(MIMEEntity.ENC_BASE64);
  //          } else if (EMBED_XML.equalsIgnoreCase(mimePartWrapper.getContentType())) {
  //            mime.setContentFromText(stream, EMBED_XML, 0);
  //            mime.encodeContent(MIMEEntity.ENC_BASE64);
  //          } else if (TEXT_HTML.equalsIgnoreCase(mimePartWrapper.getContentType())) {
  ////            System.out.println("here html");
  //            mime.setContentFromText(stream, TEXT_HTML, 0);
  //            mime.encodeContent(MIMEEntity.ENC_QUOTED_PRINTABLE);
  //          }
  //
  //          stream.close();
  //          stream.recycle();
  //          mime.recycle();
  //        }
        } catch (Exception e) {
          // TODO: Add Logging!
          e.printStackTrace();
        }
 
        // Must happen after setting all of the mime content
        String from = null; //getFrom();
        if (StringUtil.isNotEmpty(from)) {
          doc.appendItemValue("Principal", from);
          doc.appendItemValue("iNetFrom", from);
          doc.appendItemValue("$iNetPrincipal", from);
        }
 
        doc.send(false);
        doc.recycle();
 
        // Set mime conversion back to what it was originally
      } finally {
        session.setConvertMIME(convertMime);
      }

    } catch (lotus.domino.NotesException e) {
      throw new MimeEmailException(e);
    }
    }
View Full Code Here

TOP

Related Classes of com.ibm.sbt.services.client.email.MimeEmailException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.