Email's attachments showed in Outlook 2013 as .DAT

My app sends emails with attachments (pdf/xls/ecc).
Everything works fine; emails are sended and the recipient receive the emails.

This is the problem:
If I open the email through a webmail, the attachment has the correct filename, correct extension and I can open it.
If I use Outlook 2013 to open the email, the attachment has a different name and “DAT” as extension. So if I save the xxx.DAT and rename it as .PDF or .XLS, I can open it.

If I send the same email with thunderbird, the recipients receive the attachment correctly also using Outlook 2013.

I googled to search something to solve the problem, but after some test, I still got the problem.

Any idea?

Have a look at the source of the email to see the difference between the mail that Xojo sends and what Thunderbird does. Which Xojo version do you use? I’ve had a problem with getting duplicate attachment names in 2015r4. Instead of “Session Log data time.txt.gz” I’m getting “Session Log data time.txt.gzSession Log data time.txt.gz”.

How do you send email?

via SMTPSocket? or via CURLSMBS class?

Via SMTPSocket.

This is a suspected part of email’s source compared:
From Xojo code:

Content-Type: application/base64; name="CLIORD-00647-2015.pdf"; name*=utf-8''CLIORD-00647-2015.pdf x-mac-type="3F3F3F3F" x-mac-creator="3F3F3F3F" Content-transfer-encoding: Base64 Content-disposition: attachment; filename="CLIORD-00647-2015.pdf"; filename*=utf-8''CLIORD-00647-2015.pdf

From Thunderbird:

Content-Type: application/pdf; name="CLIORD-00647-2015.pdf" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="CLIORD-00647-2015.pdf"

It seems that the code generated by your Xojo app is confusing Outlook, it’s been a long time since I worked with e-mail apps, but the Content-Type: application/base64; seems like a potential suspect.

I would also send yourself a PDF via Outlook just to double check what does work in Outlook. Don’t be surprised if you get something totally different.

I had to write a program to extract the raw files from e-mails that our accountant sends, all we get is .dat files from him (he uses Outlook something or rather).

This looks like a variation of my bug with the duplicate file name. See <https://xojo.com/issue/42655>.

Try to remove the parts with name* and filename*. As far as I remember the * means concatenation.

[quote]
This looks like a variation of my bug with the duplicate file name. See Feedback Case #42655.
Try to remove the parts with name* and filename*. As far as I remember the * means concatenation.[/quote]

Yes, it seems very similar at Feedback Case #42655

This a the part of my xojo code

file = New EmailAttachment file.loadFromFile Element mail.Attachments.Append file

so the code

Content-Type: application/base64; name="CLIORD-00647-2015.pdf"; name*=utf-8''CLIORD-00647-2015.pdf x-mac-type="3F3F3F3F" x-mac-creator="3F3F3F3F" Content-transfer-encoding: Base64 Content-disposition: attachment; filename="CLIORD-00647-2015.pdf"; filename*=utf-8''CLIORD-00647-2015.pdf

is automatically inserted by Xojo and I don’t know how I can obtain a code as one generated in thunderbird

Content-Type: application/pdf; name="CLIORD-00647-2015.pdf" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="CLIORD-00647-2015.pdf"

I’ve use a simple regex to remove the parts that I don’t need.

Can you add your information to the case? Xojo can’t reproduce the problem.

The issue has been verified.

How do you use regex to remove the parts you don’t need?

I only have gz attachments. It’s working half so far. The source of the email looks good but Mail is duplicating the attachments (not the names) now.

dim temp(-1) as string = StringUtils.SplitByRegEx(MailToCompany.Source, "filename\\*.*gz", false) dim tempString as string = Join(temp, "") temp = StringUtils.SplitByRegEx(MailToCompany.Source, "name\\*.*gz", false) tempString = Join(temp, "") MailToCompany.Source = tempString

SplitByRegex:

[code] Dim out(-1) As String
Dim startPos As Integer

Dim re As New RegEx
re.SearchPattern = delimPattern
Dim rm As RegExMatch = re.Search(source)
while rm <> nil
out.Append MidB(source, startPos + 1, rm.SubExpressionStartB(0) - startPos)
startPos = re.SearchStartPosition
rm = re.Search
wend

if startPos < source.LenB then out.Append MidB(source, startPos + 1)
if UBound(out) > 0 then return out[/code]

Ugh… Mail is such a diva. Now the mails show up blank.

By first, thanks to Beatrix Willius for the EmailMessage.source tip !

I edited the EmailMessage.source with this method:

[code]Function CleanEmailSource(EmailSource as String) As String
Dim Rows() As String = Split(EmailSource, EndOfLine)

For i as integer=0 to Rows.Ubound
Dim row as String = Rows(i)
if InStr(0,Row,“x-mac-type”)>0 Then Row =""
if InStr(0,Row,“x-mac-creator”)>0 Then Row =""
if InStr(0,Row,“filename*=”)>0 or InStr(0,Row,“name*=”)>0 Then
Dim s() as String = Split(Row, “;”)
call s.Pop
Row = Join(s, “;”) + “;”
End If

rows(i)=Row

Next

Dim result as String = Join(rows, EndOfLine)

Return result
End Function
[/code]

Now the received email source has no more “filename*=” code, but using Thunderbird, the email appears as up blank also for me… but… if I open the email through webmail, it appears correctly.

After some trial and error and testing with various iphones, this code ended up working for me. The recipient received that PDF as an attachment that was recognized as a PDF.

'This code creates the correct email header
oAttachment.LoadFromFile(oFileList.Item(i))
oAttachment.MIMEType = "application/pdf"

Email Header:
Content-Type: application/pdf; name=“testfile.pdf”;
x-mac-type=“3F3F3F3F”
x-mac-creator=“3F3F3F3F”
Content-transfer-encoding: Base64
Content-disposition: attachment

[quote]Brandon Warlick

'This code creates the correct email header
oAttachment.LoadFromFile(oFileList.Item(i))
oAttachment.MIMEType = “application/pdf”[/quote]
The attachment’s filename received is the same of the one sended?

3F3F3F3F for the Mac type looks strange.

The funny thing is I’ve got 2 computers running the Captain. One shows a blank mail and the other shows the mail fine.

An old mail has the following for the attachment:

----==_mimepart_569ddc29187f9_531d3fba133aefdc366933
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=Session_Log_2016-01-19_07-37-00.txt.gz
Content-Type: application/x-gzip;
charset=UTF-8;
filename=Session_Log_2016-01-19_07-37-00.txt.gz;
name=Session_Log_2016-01-19_07-37-00.txt.gz
Content-Id: 569ddc28b03e4_531d3fba133aefdc3662c0@worker6.mail

I’ll try to get to this tomorrow.

That’s Mail deciding that you’ve already seen this content and don’t need to see it again. If you double-click the message to open a new message window, you should be able to see the entire contents.

FWIW - This mechanism is really handy when you’re viewing a long threaded email conversation :stuck_out_tongue:

I created a <https://xojo.com/issue/42788> for a similar trouble