2
votes

To exchange data with another system we send the data as an email attachment to a dedicated address. The email is generated using ActionMailer v3.2.12.

The problem is that when the email arrives at its destination, a redundant attachment named ATT00001.c is a part of the email, in addition to the attachment we created. This causes issues with the import routine at the other end.

A big part of the problem is that we know almost nothing about how the email is being handled at the destination . We also dont know what type of email server is in use and dont have access to check what the email actually looks like when it arrives. We can send it to one of our own addresses and it looks fine there.

I know this is not a lot to go on, but perhaps one of you guys have seen these ATT00001-attachments being added to machine generated emails before.

config.action_mailer.smtp_settings

address: smtp.<mailprovider>.com
port: 587
domain: ourdomain.com
authentication: login
user_name: <removed>
password: <removed>
enable_starttls_auto: false

Update: We've been able to obtain a copy of the problematic email and it shows the email body rendered after the attachment as an attachment of its own. We've tried setting ActionMailer's parts_order to make sure the attachment is generated after the email body, it did not help.

Update2: Sending to my gmail account and showing original raw data I get this.

SENT MAIL in receipt response from recipient to the correct attachment (the autocreated one creates an error log entry)

(...) cut: to from and through email header information
 Mime-Version: 1.0
Content-Type: multipart/mixed;
 charset=UTF-8
Content-Transfer-Encoding: 7bit


--
Date: Thu, 28 Feb 2013 12:15:23 +0100
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="thefile.mscons"
Content-ID: <512f3c4b6e875_a8f756dcc642fe@bjorns_arch.mail>

VU5BOisuPyAnVU5CK1VOT0M6Mys3MDgwMDAzNDExNzE2OjE0OlRJTUVSKzcw
... many more lines like this ...
ODAwMDUwNTEyMTc6MTQ6VElNRVIrMTMwMjI4OjEyMTUrUE9XRVNUMTMwMjI4

----

This is with body nil in actionmailer

Next is a RESPONSE from the recipient system, sent to my gmail. It's a receipt on the correct attachment (the extra attachement generates an error, flushing their system)

RECEIVED MAIL

(..) unintersting header stuff with addresses
Content-Disposition: attachment;
  filename="afilename.txt"
Content-Transfer-Encoding: base64
Content-Type: Application/EDIFACT; charset="iso-8859-1"
Mime-Version: 1.0
Date: Sat, 16 Feb 2013 11:07:10 +0100
From: [email protected]
To: ***@gmail.com
Subject: thesubject
Message-ID: <[email protected]>
X-TM-AS-Product-Ver: IMSS-7.0.0.6298-6.8.0.1017-19380.002
X-TM-AS-User-Approved-Sender: Yes
X-Greylist: Sender is SPF-compliant, not delayed by
milter-greylist-4.0 (isp-app27-vm.isp.example.com [213.239.116.46]);
Sat, 16 Feb 2013 11:07:11 +0100 (CET)
X-ExampleIKT-MailScanner-Information: Please contact the ISP for more information
X-ExampleIKT-MailScanner-ID: r1GA7BqD021150
X-ExampleIKT-MailScanner: Found to be clean
X-ExampleIKT-MailScanner-From: [email protected]
X-Spam-Status: No

VU5BOisuPyAnVU5CK1VOT0M6Mys3MDgwMDA1MDUxMjE3OjE0OlRJTUVSKzcwODAwMDM0MTE3MTY6
.. more..
pUSU1FUisxJ1VOVCszKzEnVU5aKzErMjAxMzAyMDAyNDg1Nzcn

something suspicious with the Content-Type? Is a new (empty) attachment generated from the stuff prior to -- in the sent email?

2
What are you using to send the email, post the relevant part of your smtp setup. ActionMailer::Base.smtp_settings = { :address => '??????', - RadBrad
The configuration have been appended to OP - Sharagoz
is that mail provider MS Exchange based? - RadBrad
No, there's no Exchange server involved at our end. Also, if it were, wouldnt we see the redundant attachment regardless of where the email was being sent? There might be an Exchange server involved at the recipients end, I dont know that yet. - Sharagoz
Googling ATT0001 returns tons of stuff about the attachment, it all seems to be exchange related, likely it's on THEIR end, also lot's of it was MAC users complaining about the issue when sending attachments to Exchange ???? - RadBrad

2 Answers

1
votes

I believe this is to do with inline attachments and Exchange server. Some clients, Apple Mail in particular allow you to add inline attachments, that is, a MIME attachment sandwiched in between text/body parts of an email. Exchange server expects that all attachments appear after any text portion of a mail.

Everything after the attachment in your mail gets treated as an attachment, so the body gets stuffed into a file and named as you reported it to be named. Seeing as you're using ActionMailer, see this answer and possible this answer, which explains that you need to switch the order of the lines of code, and possibly play with some other settings.

1
votes

Our problem is solved, though unfortunately I cant say what caused the redundant attachment. We worked around it by sending a non-multipart email that contained only the attachment. This solution obviously wont work for people who need to send a multipart email.

Sending non-multipart email with an attachment in Rails is not straight forward. You cant use the attachment helper method and a blank body, you need to put the attachment content in the email body and manually specify the disposition.

class MailMan < ActionMailer::Base
  def test
    attachment_content = "my attachment"
    disposition = "attachment; filename=\"test.txt\""
    mail(body: attachment_content,  content_disposition: disposition)
  end
end