TFileInputMail Can't retrieve mail content

One Star

TFileInputMail Can't retrieve mail content

I have a problem that seems simple to solve. In fact, I would like to work on returns mails.
To do this, I established the following sequence: tpop->tFileinputmail->....
I retrieves the address of the sender, the subject of the message. As against When I want to recover the body of the message, it is a mistake.
 connecting to socket on port 3999
Exception in component tFileInputMail_1
at mailing_s_h.t003_0_1.T003.tFileList_1Process(
at mailing_s_h.t003_0_1.T003.runJobInTOS(
at mailing_s_h.t003_0_1.T003.main(

In fact I think it freezes on the "---" because before content-type it had "---- message --- "
Can you help me please
Community Manager

Re: TFileInputMail Can't retrieve mail content

Hello Rgent
I try to reproduce your job with TOS3.0.0, but I don't get this exception, can you upload your job and send me an example of your email?
Best regards

Talend | Data Agility for Modern Business
Seventeen Stars

Re: TFileInputMail Can't retrieve mail content

it's seems to be a message "inline" with the boundary "---" to encapsulate the attachment !?

Have you got something like
Content-Type: multipart/mixed; boundary="-"

in your mail !??
One Star

Re: TFileInputMail Can't retrieve mail content

Hi Shong and kzone..
thank you for your help...i can't resolve my problem. Please see this an example of email :
Return-path: <>
Received: toto
by titi
(MDaemon PRO v9.6.5)
with ESMTP id md50000494568.msg
for ""; Mon, 13 Oct 2008 18:58:05 +0200
Authentication-Results: ""
spf=neutral smtp.mail=;
sender-id=neutral header.=;
x-ip-ptr=hardfail ""(no ptr match);
x-ip-helo=pass smtp.helo=""
x-ip-mail=pass smtp.mail= ""
X-Spam-Processed: "", Mon, 13 Oct 2008 18:58:05 +0200
(not processed: message size (52213) exceeds max size (51200))
X-MDOP-RefID: str=0001.0A0B0204.48F37D2A.00EB,ss=1,pt=60562,fgs=256 (_st=1 _vt=0 _iwf=0)
X-MDPtrLookup-Result: hardfail "" (no ptr match) ("")
X-MDHeloLookup-Result: pass ("") (""
X-MDMailLookup-Result: pass smtp.mail= ("") (""")
X-MDDKIM-Result: neutral ("")
X-Rcpt-To: ""
X-MDRcpt-To: ""
X-MDaemon-Deliver-To: ""
Received: from ("") by ("") with Microsoft SMTP Server (TLS) id; Mon, 13 Oct 2008 16:53:13 +0000
Received: from ("") by ("") with Microsoft SMTP Server id; Mon, 13 Oct 2008 16:53:13 +0000
Received: by (Postfix) id 23A096C849A; Mon, 13 Oct
2008 16:53:13 +0000 (UTC)
Date: Mon, 13 Oct 2008 16:53:13 +0000
Subject: Undelivered Mail Returned to Sender
MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status;
Message-ID: ""
X-MDAV-Processed: "", Mon, 13 Oct 2008 18:58:07 +0200
X-Antivirus: avast! (VPS 081013-0, 13/10/2008), Inbound message
X-Antivirus-Status: Clean
Content-Description: Notification
Content-Type: text/plain
This is the Postfix program at host
I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.
For further assistance, please send mail to <postmaster>
If you do so, please include this problem report. You can
delete your own text from the attached returned message.
The Postfix program
<>: host "" said: 550 #5.1.0 Address
rejected. (in reply to RCPT TO command)
Content-Description: Delivery report
Content-Type: message/delivery-status
Reporting-MTA: dns;
X-Postfix-Queue-ID: A1B036C840B
X-Postfix-Sender: rfc822; ""
Arrival-Date: Mon, 13 Oct 2008 16:53:12 +0000 (UTC)
Final-Recipient: rfc822;
Action: failed
Status: 5.0.0
Diagnostic-Code: X-Postfix; host "" said: 550 #5.1.0
Address rejected. (in reply to RCPT TO command)

In this mail, i would like to retrieve "Final-Recipient" for example.
The value is rfc822;

How can i do..
Seventeen Stars

Re: TFileInputMail Can't retrieve mail content

rfc822; is not a attribute of the "header" but of the "content Body" so i'm not sure that Talend
can do that (?) .
you can use a routine perhaps to manipulate multipart and body part (@see javamail doc)
for example i've write this one to catch attachment from a .mail
I think you can retrive your attribute in the handle part method by adding a few code :
public class extractmail {
public extractmail(){

* acesseur
// GET
public static int getNbreSauvegarde()
return nbre_sauvegarde;
public static String getNomSauvegarde()
return nom2sauvegarde;

// SET
public static void setNbreSauvegarde()
public static void setNomSauvegarde(String n2s)
nom2sauvegarde = n2s;

public static void extract(String host, String admin, String mot2passe) throws Exception
// etablir la session
Session session = Session.getDefaultInstance(System.getProperties(), null);

// protocole
Store store = session.getStore("pop3");
// connection distante
store.connect(host, admin, mot2passe);

// get folder :: INBOX pour POP3
Folder folder = store.getFolder("INBOX");
// en lecture seul !;

// récuperer les messages
Message messages[] = folder.getMessages();


catch(Exception e)
System.out.println("exception alert : " + e.getMessage());

public static void handleMultiPart(Multipart multipart) throws Exception
if(multipart.getCount() != 0)
for(int i = 0, n = multipart.getCount(); i < n; i++)
// on trate chaque partie

public static void handleParts(Part part) throws Exception
String disposition = part.getDisposition();

String contentType = part.getContentType();

String filename = part.getFileName();

if(disposition != null)
if(disposition.equalsIgnoreCase(Part.ATTACHMENT) || disposition.equalsIgnoreCase("attachement"))

public static void saveFile(InputStream inputstream) throws Exception

// sauvegarde du fichier selon la valeur return_path

File file = new File("/where/to/save/",getNomSauvegarde());
readAndWrite(file, inputstream);


public static void readAndWrite(File file, InputStream inputStream) throws Exception
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);

BufferedInputStream bis = new BufferedInputStream(inputStream);
int aByte;

while((aByte = != -1)



call it with tJavaFlex component
Hope it can help you
One Star

Re: TFileInputMail Can't retrieve mail content

Hi Kzone,
Thanks you for your help. I studie your reply. But if i understand, you give me the java code of the process.
But, it don't resolve my problem.
can i have a java code which allow to cross every email and retrieve a value of specifique line given for output.
One Star

Re: TFileInputMail Can't retrieve mail content

I was getting nullpointerexception in processing multipart attachment. TOS 4.1.2 still generates code that looks for string '=?' which is strange.
Following code, in tJava, uses mail file of tPop and downloads multipart attachment (MSexcel in my case) to local drive D:
InfoCepts fileInputtFileInputMail_1 = null;
fileInputtFileInputMail_1 = new globalMap.get("tPOP_1_CURRENT_FILEPATH")));
javax.mail.Session session_tFileInputMail_1 = javax.mail.Session.getInstance(System.getProperties(), null);
javax.mail.internet.MimeMessage msg_tFileInputMail_1 = new javax.mail.internet.MimeMessage(session_tFileInputMail_1, fileInputtFileInputMail_1);
if (msg_tFileInputMail_1.isMimeType("multipart/*")) {
javax.mail.Multipart mptFileInputMail_1 = (javax.mail.Multipart) msg_tFileInputMail_1.getContent();
String attachfileNametFileInputMail_1 = "";
String pathtFileInputMail_1 = ""; outtFileInputMail_1 = null; intFileInputMail_1 = null;
for (int i = 0; i < mptFileInputMail_1.getCount(); i++) {
javax.mail.BodyPart mparttFileInputMail_1 = mptFileInputMail_1.getBodyPart(i);
String dispositiontFileInputMail_1 = mparttFileInputMail_1.getDisposition();
if ((dispositiontFileInputMail_1 != null) && ((dispositiontFileInputMail_1.equals(javax.mail.Part.ATTACHMENT))
)) {
attachfileNametFileInputMail_1 = mparttFileInputMail_1.getFileName();
File saveFile = new File("D:/"+attachfileNametFileInputMail_1);
BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(saveFile) );
byte[] buff = new byte;
InputStream is = mparttFileInputMail_1.getInputStream();
int ret = 0, count = 0;
while( (ret = > 0 ){
bos.write(buff, 0, ret);
count += ret;
Community Manager

Re: TFileInputMail Can't retrieve mail content

Hi Rasik
Please upload some screenshot of your job.
Best regards
Talend | Data Agility for Modern Business
One Star

Re: TFileInputMail Can't retrieve mail content

I have the same problem. In some situations, depending of the mail client of the sender, the job throw a nullpointer exception, is the same scenario which someone said to fix with javaflex... my ask is:
The tFileInputMail is going to handle the type of attachments multiparts?
Thank you
Community Manager

Re: TFileInputMail Can't retrieve mail content

Hi Angel
I got the same file when testing your file, please report a a bug on bugtracker and upload an example of mail.

Best regards
Talend | Data Agility for Modern Business