Fetching mail with Excel attachment fails

One Star

Fetching mail with Excel attachment fails

Hello all,
I use tFileInputMail to retrieve an Excel attachment from an email. This is not a problem when the email has been created using Outlook and the Excel file is added as attachment.
However, when I create the Excel file and send an email from Excel, the attachment is not picked up by Talend.
It seems that the emails are different.
When attached in Outlook, the email contains different content types:
Content-Type: multipart/mixed;
Content-Type: multipart/alternative;
Content-Type: text/plain;
Content-Type: text/html;
Content-Type: application/vnd.ms-excel;
When emailed via Excel, the email only contains content type application/vnd.ms-excel
...and in this case the attachment is not being extracted.
Anybody has a solution?
Tnx in advance!
Six Stars

Re: Fetching mail with Excel attachment fails

Hey,
when sending data from Excel the content of the file is filled into the message directly, this is indicated from the MIME type. So there is no attachment and therefore Talend cannot pickup anything. I don't know if Excel has some configuration about how to send it.
Of course you could make it done by writing simple VBA module (ALT + F11) and connect it to custom button in Excel GUI.
Following code will save Active workbook, send it in Outlook way (message with attachment):
Sub Save_and_Mail_workbook_Outlook()
'Working in 2000-2010
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim OutApp As Object
Dim OutMail As Object
Set wb1 = ActiveWorkbook
If Val(Application.Version) >= 12 Then
If wb1.FileFormat = 51 And wb1.HasVBProject = True Then
MsgBox "There is VBA code in this xlsx file, there will" & vbNewLine & _
"be no VBA code in the file you send. Save the" & vbNewLine & _
"file first as xlsm and then try the macro again.", vbInformation
Exit Sub
End If
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'Make a copy of the file/Open it/Mail it/Delete it
'If you want to change the file name then change only TempFileName
TempFilePath = Environ$("temp") & "\"
TempFileName = "Copy of " & wb1.Name & " " & Format(Now, "dd-mmm-yy h-mm-ss")
FileExtStr = "." & LCase(Right(wb1.Name, _
Len(wb1.Name) - InStrRev(wb1.Name, ".", , 1)))
wb1.SaveCopyAs TempFilePath & TempFileName & FileExtStr
Set wb2 = Workbooks.Open(TempFilePath & TempFileName & FileExtStr)
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "ron@debruin.nl"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.Body = "Hi there"
.Attachments.Add wb2.FullName
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
.Send 'or use .Display
End With
On Error GoTo 0
wb2.Close SaveChanges:=False
'Delete the file
Kill TempFilePath & TempFileName & FileExtStr
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub

Ladislav
One Star

Re: Fetching mail with Excel attachment fails

Thanks for the explanation and sorry for my late reply, but this will not work in my situation. We receive emails like this from our clients. Is there absolutely no way Talend can extract the attachments? Is there another solution using a custom Java component?