Ruby Tmail Attachment name

430 views Asked by At

I am using TMail to send emails. I'm able to attach PDFs to these emails, and download them successfully. However, when I receive the email, the attachment name is 'noname'. How can I choose the name of the attachment? I know I can choose it using the mail gem.

At this point, I'm too far in the project to switch to anything else.

1

There are 1 answers

0
the Tin Man On

When you create the message you do something like:

email = TMail::Mail.new

To attach your file you do something like:

attachment = TMail::Mail.new
attachment.body = Base64.encode64(attachment_content.to_s)
attachment.transfer_encoding = "Base64"
attachment['Content-Disposition'] = "attachment; filename=#{attachment_filename}"
email.parts << attachment

It's the next to last line that should do the trick.