web stats
Reading email and attachement with Mirth - Mirth Community

Go Back   Mirth Community > Mirth Connect > General Discussion

Reply
 
Thread Tools Display Modes
  #1  
Old 03-22-2011, 03:54 AM
Aluvian Aluvian is offline
OBX.1 Kenobi
 
Join Date: Jan 2011
Posts: 26
Aluvian is on a distinguished road
Lightbulb 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


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

var list = new Packages.java.util.ArrayList();

var properties = new Packages.java.util.Properties();

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");
folder.open(2);

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 Packages.java.io.InputStream(bodyPart.getInputStre am());
var isr = new Packages.java.io.InputStreamReader(is);
var br = new Packages.java.io.BufferedReader(isr);

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

var sMsg = "Date : " + Date + "\nFrom : " + From + "\nSubject : " + Subject + "\nContent : " + Content + "\nFile : " + pj;
list.add(sMsg);
}

folder.close(true);
store.close();

return list;
Reply With Quote
  #2  
Old 03-22-2011, 04:50 AM
valentin2 valentin2 is offline
What's HL7?
 
Join Date: Mar 2011
Location: Milan
Posts: 1
valentin2 is on a distinguished road
Default

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 custom writing company.
Reply With Quote
  #3  
Old 02-26-2012, 11:16 PM
mbreithuber3008 mbreithuber3008 is offline
What's HL7?
 
Join Date: Feb 2012
Posts: 1
mbreithuber3008 is on a distinguished road
Default

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
(e139bd2e-a606-41bf-9e78-ff0b25a743d5#32)"


Line 32 is this:

var is = new Packages.java.io.InputStream(bodyPart.getInputStre am());

I don't see what's wrong with this. can anyone help me out here?
Reply With Quote
  #4  
Old 02-29-2012, 02:35 AM
Aluvian Aluvian is offline
OBX.1 Kenobi
 
Join Date: Jan 2011
Posts: 26
Aluvian is on a distinguished road
Default

I think it's a forum trouble with the quote. There's a blank in the "getInputStream".
Reply With Quote
  #5  
Old 06-05-2012, 01:07 PM
blackc2004 blackc2004 is offline
Mirth Newb
 
Join Date: Mar 2007
Location: Los Angeles, CA
Posts: 17
blackc2004
Default

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.search.FlagTerm(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?
Reply With Quote
  #6  
Old 03-08-2019, 02:25 PM
Mits87 Mits87 is offline
OBX.2 Kenobi
 
Join Date: Nov 2016
Posts: 55
Mits87 is on a distinguished road
Default

I am getting below error any suggestion?

TypeError: Cannot find function getBodyPart in object <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html dir="" lang="" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 06:12 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation