One Star

Save and Rename mail attachments

Hi.
I need to download and rename mail attachments.
I'm daily receiving an email whose subjects contain the date while the attachment name is always the same.
I need to save the attachment and RENAME it with the mail subject.
Please help.
Many thanks, in advance,
Andrea
10 REPLIES
One Star

Re: Save and Rename mail attachments

Hi Andrea
You can use tPOP component to fetch mail, use tFileInputMail to export attachments.
Then use tFileCopy to rename attachments.
Best regards,
Pedro
One Star

Re: Save and Rename mail attachments

Hi Pedro.
Thanks for your answer ....
Just a couple of questions:
1) using the tInputMail I've the problem that it overwrites the attachments file if I'm gettingm ore than one un-read email ...
a possibile workaround is to extract only one email anceh then using a LOOP to downaload all the emails...any other ideas ?
2) using the tFileCopy, how can I pass to it the email subject to compose the new attachment name ? (sorry but I'm very new using Talend)
Thanks,
Andrea
One Star

Re: Save and Rename mail attachments

Hi Andrea
1)
You can set "Attachment export directory" of tFileInputMail like this to avoid overwriting.
"E:/Attachment/"+context.sequence+"/"                   //context.sequence will be increased by tJava(context.sequence++)

Export each attachment into an unique directory.
2) You can set "Mail parts" of tFileInputMail as follows. Then extract this field into a variable.
Column   Mail part
Object "Subject"

Regards,
Pedro
One Star

Re: Save and Rename mail attachments

1) You can set "Attachment export directory" of tFileInputMail like this to avoid overwriting.
"E:/Attachment/"+context.sequence+"/"                   //context.sequence will be increased by tJava(context.sequence++)

Ok, I'm going to try this ... but I'll nedd a way to give the exact name (related to the subject) to the proper directory attachment ...
2) You can set "Mail parts" of tFileInputMail as follows. Then extract this field into a variable.
Column   Mail part
Object "Subject"

I did it .. I'm writing a csv file with the sender and subject of the downloaded emails ...
My problem is to pass the subject to che tCOPY.
Thanks,
Andrea
One Star

Re: Save and Rename mail attachments

Hi Andrea
To pass the subject to tCopy.
You can create job as the following images with the csv file.
Regards,
Pedro
One Star

Re: Save and Rename mail attachments

It works !
Many many thanks
One Star

Re: Save and Rename mail attachments

Just another question ... is it possible to get the attachment name ?
Andrea
One Star

Re: Save and Rename mail attachments

Hi
No. It's impossible to get the attachment name directly now.
Regards,
Pedro
One Star

Re: Save and Rename mail attachments

Hi, can you please explain exactly, how I can detach the attachments with tInputMail?
The original filename is in my case in the subject ...
One Star

Re: Save and Rename mail attachments

Hi St_germain
tFileInputMail can detach attachments automatically if you offer correct path for "Attachment export directory".
Regards,
Pedro