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
connected
Exception in component tFileInputMail_1
java.lang.NullPointerException
at mailing_s_h.t003_0_1.T003.tFileList_1Process(T003.java:711)
at mailing_s_h.t003_0_1.T003.runJobInTOS(T003.java:1250)
at mailing_s_h.t003_0_1.T003.main(T003.java:1160)
disconnected.

In fact I think it freezes on the "---" because before content-type it had "---- message --- "
Can you help me please
Thanks
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

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Seventeen Stars

Re: TFileInputMail Can't retrieve mail content

hi,
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 smtp.helo=WA2EHSNDR005.bigfishoshf.com ("") ("".s-h.fr)
X-MDMailLookup-Result: pass smtp.mail= ("") (""")
X-MDDKIM-Result: neutral ("")
X-Rcpt-To: ""
X-MDRcpt-To: ""
X-MDRemoteIP:""
X-Return-Path:
X-Envelope-From:
X-MDaemon-Deliver-To: ""
Received: from WA4EHSOBE002.bigfishoshf.com ("") by
WA2EHSNDR005.bigfishoshf.com ("") with Microsoft SMTP Server (TLS) id
8.1.240.5; Mon, 13 Oct 2008 16:53:13 +0000
Received: from mail178-wa4-R.bigfishoshf.com ("") by
WA4EHSOBE002.bigfishoshf.com ("") with Microsoft SMTP Server id
8.1.240.5; Mon, 13 Oct 2008 16:53:13 +0000
Received: by mail178-wa4-R.bigfishoshf.com (Postfix) id 23A096C849A; Mon, 13 Oct
2008 16:53:13 +0000 (UTC)
Date: Mon, 13 Oct 2008 16:53:13 +0000
From: MAILER-DAEMON
Subject: Undelivered Mail Returned to Sender
To:""
MIME-Version: 1.0
Content-Type: multipart/report; report-type=delivery-status;
boundary="A1B036C840B.1223916793/mail178-wa4-R.bigfishoshf.com"
Message-ID: ""
Reply-To: MAILER-DAEMON
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
--A1B036C840B.1223916793/mail178-wa4-R.bigfishoshf.com
Content-Description: Notification
Content-Type: text/plain
This is the Postfix program at host mail178-wa4-R.bigfishoshf.com.
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
<mail@mmmmmm.com>: host "" said: 550 #5.1.0 Address
rejected. (in reply to RCPT TO command)
--A1B036C840B.1223916793/mail178-wa4-R.bigfishoshf.com
Content-Description: Delivery report
Content-Type: message/delivery-status
Reporting-MTA: dns; mail178-wa4-R.bigfishoshf.com
X-Postfix-Queue-ID: A1B036C840B
X-Postfix-Sender: rfc822; ""
Arrival-Date: Mon, 13 Oct 2008 16:53:12 +0000 (UTC)
Final-Recipient: rfc822; mail@mmmmmm.com
Action: failed
Status: 5.0.0
Diagnostic-Code: X-Postfix; host "" said: 550 #5.1.0
Address rejected. (in reply to RCPT TO command)
--A1B036C840B.1223916793/mail178-wa4-R.bigfishoshf.com--

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

How can i do..
thank
Seventeen Stars

Re: TFileInputMail Can't retrieve mail content

rfc822; mail@mmmmmm.com 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()
{
nbre_sauvegarde++;
}
public static void setNomSauvegarde(String n2s)
{
nom2sauvegarde = n2s;
}

public static void extract(String host, String admin, String mot2passe) throws Exception
{
try
{
// 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 !
folder.open(Folder.READ_ONLY);

// 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
handleParts(multipart.getBodyPart(i));
}
}
}

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"))
{
setNomSauvegarde(filename);
saveFile(part.getInputStream());
}
}
}


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);

}/*saveFile*/


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 = bis.read()) != -1)
{
bos.write(aByte);
}


bos.flush();
bos.close();
bis.close();
}/*readAndWrite*/

}

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.
Thanks
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:
-Rasik
InfoCepts
java.io.FileInputStream fileInputtFileInputMail_1 = null;
fileInputtFileInputMail_1 = new java.io.FileInputStream(((String) 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 = "";
java.io.BufferedOutputStream outtFileInputMail_1 = null;
java.io.BufferedInputStream 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();
System.out.println(attachfileNametFileInputMail_1);
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 = is.read(buff)) > 0 ){
bos.write(buff, 0, ret);
count += ret;
}
bos.close();
is.close();
}
}
}
Community Manager

Re: TFileInputMail Can't retrieve mail content

Hi Rasik
Please upload some screenshot of your job.
Best regards
Shong
----------------------------------------------------------
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
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business