Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attachments are ignoring filename when sent using ActionMailer #82

Closed
rmcsharry opened this issue Feb 21, 2017 · 11 comments
Closed

Attachments are ignoring filename when sent using ActionMailer #82

rmcsharry opened this issue Feb 21, 2017 · 11 comments

Comments

@rmcsharry
Copy link

rmcsharry commented Feb 21, 2017

I have Rails 5.0.1 using ActionMailer code as follows:

  def pdf_quote(proposal)
    @proposal = proposal
    email_with_name = %("#{@proposal.first_name} #{@proposal.last_name}" <#{@proposal.email}>)
    @filename = "QD-#{@proposal.qd_number}_#{@proposal.last_name}.pdf"
    attachments[@filename] = {
      mime_type: 'application/pdf',
      encoding: 'Base64',
      content: @proposal.pdf_base64
    }  
    mail(
      to: email_with_name,
      from: 'Floorbook UK <email address>',
      subject: 'Your Personal Flooring Quote is attached',
      sent_on: Time.now
      )    
  end

I have tried by hardcoding 'test.pdf' also. I have tried replace flilename: with remoteName inside the hash (as I see th PHP plugin uses remoteName).

No matter what I try the filename does not appear in the JSON in the mailgun logs.

I can however see it in the Rails log. For example, here is the log when I tried using remotename:

----==_mimepart_58acb0bbc5906_b35a3ff9c303fa14374b
Content-Type: application/pdf
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
 filename=QD-1002_McSharry.pdf
remotename: QD-1002_McSharry.pdf
Content-ID: <58acb0bbc8aaf_b35a3ff9c303fa14376d9@Richards-MacBook-Air.local.mail>

%PDF-1.3

Here is the relevant part of the JSON from the mailgun log:

"message": {
"headers": {
"to": "Richard McSharry ",
"message-id": "20170221213251.124698.55612.AAE859F0@sandbox4d05645e78ac4c81b7b542d27c5e87ad.mailgun.org",
"from": "Floorbook UK ",
"subject": "Your Personal Flooring Quote is attached"
},
"attachments": [
{
"filename": "",
"content-type": "application/pdf",
"size": 9004
}
],
"recipients": [
"my email"
],
"size": 11517
},

@pirogoeth
Copy link
Contributor

@rmcsharry I'm assuming this is with the new Railgun code / version 1.1.4 of the gem?

@rmcsharry
Copy link
Author

rmcsharry commented Feb 23, 2017

Yes - mailgun-ruby (1.1.4). I also tested with Postman and the filename there shows up as 'pd_mime_attachment'.

So it seems both gmail and postman see that the filename is empty and substitute a default value.

I suppose it could be ActionMailer doing this, but then surely Stack Overflow would be swamped with questions about this? It used to happen in Rails 3. I've opened a question anyway for Rails 5 to see if anyone else has seen this in ActionMailer specifically.

@pirogoeth
Copy link
Contributor

@rmcsharry I will look in to this, it very well could be an issue with Railgun. I'll let you know what I find :)

@pirogoeth
Copy link
Contributor

@rmcsharry I think I found the issue. Stand by for a PR.

pirogoeth added a commit that referenced this issue Feb 24, 2017
@rmcsharry
Copy link
Author

@pirogoeth Awesome, thanks for the quick fix. I just tested it and it works! :)

@pirogoeth
Copy link
Contributor

@rmcsharry Awesome! I'll cut an official release on Monday :)

@rmcsharry
Copy link
Author

@pirogoeth This branch I tested was labelled as version 1.1.5. But now that you have merged it, the version of master branch did not change, it is still 1.1.4 - was that the intention?

@rmcsharry rmcsharry reopened this Mar 7, 2017
@pirogoeth
Copy link
Contributor

@rmcsharry It seems that 1.1.5 has been released to Rubygems and 1.1.5 is in master (tagged as v1.1.5)..

@rmcsharry
Copy link
Author

Ok thanks I just removed it from my project and bundle installed again, now it shows up as 1.1.5. Thanks for confirming!

@pirogoeth
Copy link
Contributor

Of course!

@pavanscs
Copy link

pavanscs commented Feb 22, 2021

new issues can any one please help me with this i want a attachment file that was send to the mailer has to be open in a new tab is it possible to make the pdf file to open in a new tab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants