コード例 #1
0
ファイル: NewProviderSupport.java プロジェクト: phcd/TAB
  /**
   * Deliveres notification to the user that an email has been dropped. Typically due to size
   * restriction
   *
   * @param account
   * @param messageNumber
   * @param message
   * @throws Exception
   */
  public void saveMessageDroppedNotification(
      Account account, int messageNumber, Message message, int reportedSize) throws Exception {
    MessageParser parser = new MessageParser();

    Email email = new Email();
    email.setSubject(
        "Your email"); // ReceiverUtilsTools.subSubject(parser.parseMsgSubject(message),
                       // subjectSize));
    email.setFrom(parser.parseMsgAddress(message, "FROM", false));
    email.setTo(ReceiverUtilsTools.subAddress(parser.parseMsgAddress(message, "TO", true)));
    email.setCc(ReceiverUtilsTools.subAddress(parser.parseMsgAddress(message, "CC", true)));
    email.setBcc(ReceiverUtilsTools.subAddress(parser.parseMsgAddress(message, "BCC", true)));
    email.setMaildate(ReceiverUtilsTools.dateToStr(message.getSentDate()));
    email.setStatus("0");
    email.setUserId(account.getUser_id());
    email.setMessage_type("EMAIL");

    Body body = new Body();

    String droppedMessage =
        getEmailDroppedMessage(account, getMessageDate(message), reportedSize, email.getFrom());

    body.setData(droppedMessage.getBytes());
    email.setBodySize(droppedMessage.length());

    int saveStatus = DALDominator.newSaveMail(account, email, body);

    if (log.isDebugEnabled())
      log.debug(
          String.format(
              "[%s] msgNum=%d, saving completed for dropped message with status %s",
              account.getName(), messageNumber, saveStatus));
  }
コード例 #2
0
ファイル: SendGrid.java プロジェクト: amitquill/GNPNew
  public HttpEntity buildBody(Email email) {
    MultipartEntityBuilder builder = MultipartEntityBuilder.create();

    // We are using an API key
    if (this.username != null) {
      builder.addTextBody("api_user", this.username);
      builder.addTextBody("api_key", this.password);
    }

    String[] tos = email.getTos();
    String[] tonames = email.getToNames();
    String[] ccs = email.getCcs();
    String[] bccs = email.getBccs();

    // If SMTPAPI Header is used, To is still required. #workaround.
    if (tos.length == 0) {
      builder.addTextBody(
          String.format(PARAM_TO, 0), email.getFrom(), ContentType.create(TEXT_PLAIN, UTF_8));
    }
    for (int i = 0, len = tos.length; i < len; i++)
      builder.addTextBody(PARAM_TO, tos[i], ContentType.create("text/plain", "UTF-8"));
    for (int i = 0, len = tonames.length; i < len; i++)
      builder.addTextBody(PARAM_TONAME, tonames[i], ContentType.create("text/plain", "UTF-8"));
    for (int i = 0, len = ccs.length; i < len; i++)
      builder.addTextBody(PARAM_CC, ccs[i], ContentType.create("text/plain", "UTF-8"));
    for (int i = 0, len = bccs.length; i < len; i++)
      builder.addTextBody(PARAM_BCC, bccs[i], ContentType.create(TEXT_PLAIN, UTF_8));
    // Files
    if (email.getAttachments().size() > 0) {
      Iterator it = email.getAttachments().entrySet().iterator();
      while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        builder.addBinaryBody(
            String.format(PARAM_FILES, entry.getKey()), (InputStream) entry.getValue());
      }
    }

    if (email.getContentIds().size() > 0) {
      Iterator it = email.getContentIds().entrySet().iterator();
      while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        builder.addTextBody(
            String.format(PARAM_CONTENTS, entry.getKey()), (String) entry.getValue());
      }
    }

    if (email.getHeaders().size() > 0)
      builder.addTextBody(
          PARAM_HEADERS,
          new JSONObject(email.getHeaders()).toString(),
          ContentType.create(TEXT_PLAIN, UTF_8));

    if (email.getFrom() != null && !email.getFrom().isEmpty())
      builder.addTextBody(PARAM_FROM, email.getFrom(), ContentType.create(TEXT_PLAIN, UTF_8));

    if (email.getFromName() != null && !email.getFromName().isEmpty())
      builder.addTextBody(
          PARAM_FROMNAME, email.getFromName(), ContentType.create(TEXT_PLAIN, UTF_8));

    if (email.getReplyTo() != null && !email.getReplyTo().isEmpty())
      builder.addTextBody(PARAM_REPLYTO, email.getReplyTo(), ContentType.create(TEXT_PLAIN, UTF_8));

    if (email.getSubject() != null && !email.getSubject().isEmpty())
      builder.addTextBody(PARAM_SUBJECT, email.getSubject(), ContentType.create(TEXT_PLAIN, UTF_8));

    if (email.getHtml() != null && !email.getHtml().isEmpty())
      builder.addTextBody(PARAM_HTML, email.getHtml(), ContentType.create(TEXT_PLAIN, UTF_8));

    if (email.getText() != null && !email.getText().isEmpty())
      builder.addTextBody(PARAM_TEXT, email.getText(), ContentType.create(TEXT_PLAIN, UTF_8));

    String tmpString = email.smtpapi.jsonString();
    if (!tmpString.equals("{}"))
      builder.addTextBody(PARAM_XSMTPAPI, tmpString, ContentType.create(TEXT_PLAIN, UTF_8));

    return builder.build();
  }