No announcement yet.

Reading email and attachement with Mirth

  • Filter
  • Time
  • Show
Clear All
new posts

  • Reading email and attachement with Mirth

    Hi all,

    I'd like to share a javascript reader with the community. The aim is to read email with attachement using the imap protocol.

    The javascript reader below do :

    - connection with the mail server
    - loading the inbox folder
    - reading messages
    - parsing mail rows (date, from, subject, ...)
    - read the 1st attachement such as an hl7 flat file

    Note :

    - it won't work with encrypted email
    - the content might be different depending on using text mail or MIME mail

    Best regards

    var host = "mailserver";
    var user = "xxx";
    var pwd = "yyy";

    var list = new;

    var properties = new;

    properties.setProperty("mail.imap.debug", "true");
    properties.setProperty("mail.imap.auth.plain.disab le", "true");
    properties.setProperty("mail.imap.port", "143");

    var session = new Packages.javax.mail.Session.getInstance(properties );

    var store = session.getStore("imap");
    store.connect(host, user, pwd);

    var folder = store.getFolder("inbox");;

    var ListMail = folder.getMessages();

    for (i = 0 ; i < ListMail.length ; i++)
    var Date = ListMail[i].getSentDate();
    var From = ListMail[i].getFrom()[0];
    var Subject = ListMail[i].getSubject();
    var Content = ListMail[i].getContent();

    var multipart = ListMail[i].getContent();
    var bodyPart = multipart.getBodyPart(1);
    var is = new am());
    var isr = new;
    var br = new;

    var pj = "";
    var lg = "";
    while ((lg = br.readLine()) != null)
    pj = pj + lg;

    var sMsg = "Date : " + Date + "\nFrom : " + From + "\nSubject : " + Subject + "\nContent : " + Content + "\nFile : " + pj;


    return list;

  • #2
    interesting information!!! thank you!!!
    It is not truly handy to invent novel drafts. You shall use much beneficial literature and create your keen work. Still products will be not really progressive. It usually happens mutedly with me. I ordinarily have many tips, amusing thoughts; therefore I could to unveil them in desirable discourse, that’s why frequently I look the support of .


    • #3
      hi! tried to use the provided code, but I get the following error message.

      "Error in connector "JavaScript Reader" at Javascript:
      Error on line 32: missing ) after argument list

      Line 32 is this:

      var is = new am());

      I don't see what's wrong with this. can anyone help me out here?


      • #4
        I think it's a forum trouble with the quote. There's a blank in the "getInputStream".


        • #5
          Hi, I'm trying to use this code to connect to imap, I can get it to connect but it reads all the emails, not just the unread ones. I've found this code:
          var ft = new packages.javax.mail.Flags(Flags.Flag.Seen), false);

          But it gives me the error:
          ReferenceError "Flags" is not defined.

          Can anyone help with this, is there a better way to only get unread messages?


          • #6
            I am getting below error any suggestion?

            TypeError: Cannot find function getBodyPart in object <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ""><html dir="" lang="" xmlns=""> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />