Examples of SMTPMessage


Examples of com.dumbster.smtp.SmtpMessage

        });
    }

    private SmtpMessage getEmail() {
        Iterator inbox = emailServer.getReceivedEmail();
        SmtpMessage email = (SmtpMessage) inbox.next();
        // clear mock-inbox for other tests
        inbox.remove();
        return email;
    }
View Full Code Here

Examples of com.dumbster.smtp.SmtpMessage

    private SmtpMessage getMockEmail(String message){
        return getMockEmail(message, "");
    }

    private SmtpMessage getMockEmail(String message, String encoding){
        SmtpMessage email = mock(SmtpMessage.class);
        when(email.getBody()).thenReturn(message);
        when(email.getHeaderValue(EmailHeader.CONTENT_TRANSFER_ENCODING.getValue())).thenReturn(encoding);

        return email;
    }
View Full Code Here

Examples of com.dumbster.smtp.SmtpMessage

        // Wait till email is received by mock smtp
        DELIVER_CHECK: for (int i = 0; i < REDELIVERY_LIMIT; i++) {
            Thread.sleep(7000);
            if (AbstractEmailServerRunner.emailServer.getReceivedEmailSize() > 0) {
                Iterator inbox = AbstractEmailServerRunner.emailServer.getReceivedEmail();
                SmtpMessage email;
                while(inbox.hasNext()) {
                    email = (SmtpMessage) inbox.next();
                    if(predicate.apply(email)){
                        break DELIVER_CHECK;
                    }
View Full Code Here

Examples of com.dumbster.smtp.SmtpMessage

     * @return EmailMessage object representing mock email or null if no email found
     */
    public static EmailMessage getFirstEmailFromInbox() {
        Iterator inbox = AbstractEmailServerRunner.emailServer.getReceivedEmail();
        if (inbox.hasNext()) {
            SmtpMessage email = (SmtpMessage) inbox.next();
            inbox.remove();
            return new EmailMessage(email);
        } else {
            return null;
        }
View Full Code Here

Examples of com.dumbster.smtp.SmtpMessage

     * @return EmailMessage object representing mock email
     */
    private static EmailMessage getLatestEmailByData(Predicate<SmtpMessage> predicate) {
        List<SmtpMessage> foundEmails = new ArrayList<SmtpMessage>();
        Iterator inbox = AbstractEmailServerRunner.emailServer.getReceivedEmail();
        SmtpMessage email;
        while (inbox.hasNext()) {
            email = (SmtpMessage) inbox.next();
            if(predicate.apply(email)){
                foundEmails.add(email);
                inbox.remove();
View Full Code Here

Examples of com.dumbster.smtp.SmtpMessage

    processor.process(message);

    Assert.assertTrue(server.getReceivedEmailSize() == 1);

    SmtpMessage email = (SmtpMessage) server.getReceivedEmail().next();
    Assert.assertTrue(email.getHeaderValue("Subject").equals("Mokai Message"));
    Assert.assertTrue(email.getHeaderValue("From").equals("mokai@localhost.com"));
    Assert.assertTrue(email.getBody().equals("This is a test"));

    server.stop();
  }
View Full Code Here

Examples of com.dumbster.smtp.SmtpMessage

    processor.process(message);

    Assert.assertTrue(server.getReceivedEmailSize() == 1);

    SmtpMessage email = (SmtpMessage) server.getReceivedEmail().next();
    Assert.assertTrue(email.getHeaderValue("Subject").equals("This is the subject"));
    Assert.assertTrue(email.getHeaderValue("From").equals("test@localhost"));
    Assert.assertTrue(email.getBody().equals("This is a test"));

    server.stop();
  }
View Full Code Here

Examples of com.elastisys.scale.commons.net.smtp.SmtpMessage

    String alertMessage = JsonUtils.toPrettyString(JsonUtils
        .toJson(taggedAlert));
    try {
      LOG.debug("sending alert to {}: {}",
          this.sendSettings.getRecipients(), alert);
      SmtpMessage email = new SmtpMessage(
          this.sendSettings.getRecipients(),
          this.sendSettings.getSender(),
          this.sendSettings.getSubject(), alertMessage, UtcTime.now());
      new SmtpSender(email, this.smtpServerSettings).call();
    } catch (Exception e) {
View Full Code Here

Examples of com.sun.mail.smtp.SMTPMessage

  }

  if (sEncoding==null) sEncoding = "ASCII";
  String sCharEnc = Charset.forName(sEncoding).name();
   
  SMTPMessage oSentMessage = new SMTPMessage(getSmtpSession());

  MimeBodyPart oMsgPlainText = new MimeBodyPart();
  MimeMultipart oSentMsgParts = new MimeMultipart("mixed");

  if (sContentType.equalsIgnoreCase("html")) {

    MimeMultipart oHtmlRelated  = new MimeMultipart("related");
    MimeMultipart oTextHtmlAlt  = new MimeMultipart("alternative");

    // ************************************************************************
    // Replace image CIDs

    HashMap oDocumentImages = new HashMap(23);

    StringSubstitution oSrcSubs = new StringSubstitution();

    Parser oPrsr = Parser.createParser(sHtmlBody, sEncoding);

    String sCid, sSrc;

    try {

      if (sTextBody==null) {
          // ****************************
          // Extract plain text from HTML
          if (DebugFile.trace) DebugFile.writeln("new StringBean()");

          StringBean oStrBn = new StringBean();

          try {
            oPrsr.visitAllNodesWith (oStrBn);
          } catch (ParserException pe) {
          throw new MessagingException(pe.getMessage(), pe);
          }

          sTextBody = oStrBn.getStrings();

          oStrBn = null;
      } // fi (sTextBody==null)

      // *******************************
      // Set plain text alternative part

      oMsgPlainText.setDisposition("inline");
      oMsgPlainText.setText(sTextBody, sCharEnc, "plain");
      // oMsgPlainText.setContent(sTextBody, "text/plain; charset="+sCharEnc);
      if (DebugFile.trace) DebugFile.writeln("MimeBodyPart(multipart/alternative).addBodyPart(text/plain)");
      oTextHtmlAlt.addBodyPart(oMsgPlainText);

      // *****************************************
      // Iterate images from HTML and replace CIDs

      NodeList oCollectionList = new NodeList();
      TagNameFilter oImgFilter = new TagNameFilter ("IMG");
      for (NodeIterator e = oPrsr.elements(); e.hasMoreNodes();)
        e.nextNode().collectInto(oCollectionList, oImgFilter);

      final int nImgs = oCollectionList.size();

      if (DebugFile.trace) DebugFile.writeln("NodeList.size() = " + String.valueOf(nImgs));

      for (int i=0; i<nImgs; i++) {

        sSrc = ((ImageTag) oCollectionList.elementAt(i)).extractImageLocn();

        // Keep a reference to every related image name so that the same image is not included twice in the message
        if (!oDocumentImages.containsKey(sSrc)) {

          // Find last slash from image url
          int iSlash = sSrc.lastIndexOf('/');

          // Take image name
          if (iSlash>=0) {
            while (sSrc.charAt(iSlash)=='/') { if (++iSlash==sSrc.length()) break; }
            sCid = sSrc.substring(iSlash);
          }
          else {
            sCid = sSrc;
          }

          //String sUid = Gadgets.generateUUID();
          //sCid = sUid.substring(0,12)+"$"+sUid.substring(12,20)+"$"+sUid.substring(20,28)+"@hipergate.org";

          if (DebugFile.trace) DebugFile.writeln("HashMap.put("+sSrc+","+sCid+")");

          oDocumentImages.put(sSrc, sCid);
        } // fi (!oDocumentImages.containsKey(sSrc))

        try {
          Pattern oPattern = oCompiler.compile(sSrc, Perl5Compiler.SINGLELINE_MASK);
          oSrcSubs.setSubstitution("cid:"+oDocumentImages.get(sSrc));
          if (DebugFile.trace) DebugFile.writeln("Util.substitute([PatternMatcher],"+ sSrc + ",cid:"+oDocumentImages.get(sSrc)+",...)");
          sHtmlBody = Util.substitute(oMatcher, oPattern, oSrcSubs, sHtmlBody);
        } catch (MalformedPatternException neverthrown) { }

      } // next
    }
    catch (ParserException pe) {
      if (DebugFile.trace) {
        DebugFile.writeln("org.htmlparser.util.ParserException " + pe.getMessage());
      }
    }
    // End replace image CIDs
    // ************************************************************************

    // ************************************************************************
    // Add HTML related images

    if (oDocumentImages.isEmpty()) {
        // Set HTML part
        MimeBodyPart oMsgHtml = new MimeBodyPart();
        oMsgHtml.setDisposition("inline");
        oMsgHtml.setText(sHtmlBody, sCharEnc, "html");
        // oMsgHtml.setContent(sHtmlBody, "text/html; charset="+sCharEnc);
        oTextHtmlAlt.addBodyPart(oMsgHtml);
    } else {

      // Set HTML text related part

      MimeBodyPart oMsgHtmlText = new MimeBodyPart();
      oMsgHtmlText.setDisposition("inline");
      oMsgHtmlText.setText(sHtmlBody, sCharEnc, "html");
      // oMsgHtmlText.setContent(sHtmlBody, "text/html; charset="+sCharEnc);
      if (DebugFile.trace) DebugFile.writeln("MimeBodyPart(multipart/related).addBodyPart(text/html)");
      oHtmlRelated.addBodyPart(oMsgHtmlText);

      // Set HTML text related inline images

      Iterator oImgs = oDocumentImages.keySet().iterator();

      while (oImgs.hasNext()) {
        BodyPart oImgBodyPart = new MimeBodyPart();

        sSrc = (String) oImgs.next();
        sCid = (String) oDocumentImages.get(sSrc);

        if (sSrc.startsWith("www."))
          sSrc = "http://" + sSrc;

        if (sSrc.startsWith("http://") || sSrc.startsWith("https://")) {
          oImgBodyPart.setDataHandler(new DataHandler(new URL(Hosts.resolve(sSrc))));
        }
        else {
          oImgBodyPart.setDataHandler(new DataHandler(new FileDataSource((sBasePath==null ? "" : sBasePath)+sSrc)));
        }

        oImgBodyPart.setDisposition("inline");
        oImgBodyPart.setHeader("Content-ID", sCid);
        oImgBodyPart.setFileName(sCid);

        // Add image to multi-part
        if (DebugFile.trace) DebugFile.writeln("MimeBodyPart(multipart/related).addBodyPart("+sCid+")");
        oHtmlRelated.addBodyPart(oImgBodyPart);
      } // wend

      // Set html text alternative part (html text + inline images)
      MimeBodyPart oTextHtmlRelated = new MimeBodyPart();
      oTextHtmlRelated.setContent(oHtmlRelated);
      if (DebugFile.trace) DebugFile.writeln("MimeBodyPart(multipart/alternative).addBodyPart(multipart/related)");
      oTextHtmlAlt.addBodyPart(oTextHtmlRelated);
    }

    // ************************************************************************
    // Create message to be sent and add main text body to it

    if (aAttachmentsPath==null) {
      oSentMessage.setContent(oTextHtmlAlt);
    } else {
      MimeBodyPart oMixedPart = new MimeBodyPart();
      oMixedPart.setContent(oTextHtmlAlt);
      oSentMsgParts.addBodyPart(oMixedPart);
    }

  } else { // (sContentType=="plain")

    // *************************************************
    // If this is a plain text message just add the text

    if (aAttachmentsPath==null) {
      oSentMessage.setText(sTextBody, sCharEnc);
    } else {
      oMsgPlainText.setDisposition("inline");
      oMsgPlainText.setText(sTextBody, sCharEnc, "plain");
      //oMsgPlainText.setContent(sTextBody, "text/plain; charset="+sCharEnc);
      if (DebugFile.trace) DebugFile.writeln("MimeBodyPart(multipart/mixed).addBodyPart(text/plain)");
      oSentMsgParts.addBodyPart(oMsgPlainText);
    }
  }
  // fi (sContentType=="html")

  // ************************************************************************
  // Add attachments to message to be sent

  if (aAttachmentsPath!=null) {
    final int nAttachments = aAttachmentsPath.length;

    FileSystem oFS = new FileSystem();
    for (int p=0; p<nAttachments; p++) {
      String sFilePath = aAttachmentsPath[p];
      if (sBasePath!=null) {
        if (!sFilePath.startsWith(sBasePath))
          sFilePath = sBasePath + sFilePath;
      }
      File oFile = new File(sFilePath);
     
      MimeBodyPart oAttachment = new MimeBodyPart();
      oAttachment.setDisposition("attachment");
      oAttachment.setFileName(oFile.getName());
      oAttachment.setHeader("Content-Transfer-Encoding", "base64");

      ByteArrayDataSource oDataSrc;
      try {
        oDataSrc = new ByteArrayDataSource(oFS.readfilebin(sFilePath), "application/octet-stream");
      } catch (com.enterprisedt.net.ftp.FTPException ftpe) {
      throw new IOException(ftpe.getMessage());
      }
      oAttachment.setDataHandler(new DataHandler(oDataSrc));
      oSentMsgParts.addBodyPart(oAttachment);
    } // next
    oSentMessage.setContent(oSentMsgParts);
  } // fi (iDraftParts>0)

  if (null!=sSubject) oSentMessage.setSubject(sSubject);

  if (sId!=null)
    if (sId.trim().length()>0)
      oSentMessage.setContentID(sId);

  if (DebugFile.trace) {
    DebugFile.decIdent();
    DebugFile.writeln("End SessionHandler.composeMessage()");
  }
View Full Code Here

Examples of com.sun.mail.smtp.SMTPMessage

          if (sRecipientAddr.length()>0) {
            try {
              String sUniqueId = sId+"."+String.valueOf(r+1);
              oMap.remove("Message.id");
              oMap.put("Message.id", sUniqueId);             
              SMTPMessage oCurrentMsg = composeMessage(sSubject, sEncoding, oRpl.replace(oTextBody, oMap), oRpl.replace(oHtmlBody, oMap), sUniqueId, aAttachmentsPath, sUserDir);
              oCurrentMsg.setFrom(new InternetAddress(sFromAddr, null==sFromPersonal ? sFromAddr : sFromPersonal));
              if (null!=sReplyAddr) oCurrentMsg.setReplyTo(new Address[]{new InternetAddress(sReplyAddr)});
              if (DebugFile.trace) DebugFile.writeln("SMTPMessage.setRecipient("+aRecType[r]+","+sRecipientAddr+")");
              oCurrentMsg.setRecipient(aRecType[r], new InternetAddress(sRecipientAddr));     
              sendMessage(oCurrentMsg);
              oOut.println("OK "+sRecipientAddr);
              nSend++;
            } catch (Exception xcpt) {
              if (oOut==null) {
                if (DebugFile.trace) DebugFile.writeln("ERROR "+aRecipients[r]+" "+xcpt.getClass().getName()+" "+xcpt.getMessage());
              } else {
                oOut.println("ERROR at SessionHandler.sendMessage() "+aRecipients[r]+" "+xcpt.getClass().getName()+" "+xcpt.getMessage());
              } // fi (oOut)
            }
          } // fi (sRecipientAddr!="")
        } // next     
    } else {
        for (int r=0; r<nRecipients; r++) {
          String sRecipientAddr = Gadgets.removeChars(aRecipients[r], " \t\r\n");
          if (sRecipientAddr.length()>0) {
            SMTPMessage oMasterMsg = composeMessage(sSubject, sEncoding, sTextBody, sHtmlBody, null, aAttachmentsPath, sUserDir);
            oMasterMsg.setFrom(new InternetAddress(sFromAddr, null==sFromPersonal ? sFromAddr : sFromPersonal));
            if (null!=sReplyAddr) oMasterMsg.setReplyTo(new Address[]{new InternetAddress(sReplyAddr)});
            try {
              if (DebugFile.trace) DebugFile.writeln("new SMTPMessage()");
              SMTPMessage oCurrentMsg = new SMTPMessage (oMasterMsg);
              if (DebugFile.trace) DebugFile.writeln("SMTPMessage.setContentID("+sId+"."+String.valueOf(r+1)+")");
              oCurrentMsg.setContentID(sId+"."+String.valueOf(r+1));
              if (DebugFile.trace) DebugFile.writeln("SMTPMessage.setRecipient("+aRecType[r]+","+sRecipientAddr+")");
              oCurrentMsg.setRecipient(aRecType[r], new InternetAddress(sRecipientAddr));     
              sendMessage(oCurrentMsg);
              oOut.println("OK "+sRecipientAddr);
              nSend++;
            }
            catch (Exception xcpt) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.