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

Problems with nesting of multipart message with pdf-attachment #78

Open
whysthatso opened this issue Mar 22, 2019 · 7 comments
Open

Problems with nesting of multipart message with pdf-attachment #78

whysthatso opened this issue Mar 22, 2019 · 7 comments
Assignees

Comments

@whysthatso
Copy link

also discussed in the chat
i have this mailer:

# locals: tempfile, client_contact_email, test_mail

module Mailers
  class Invoice
    include Hanami::Mailer

    from '<admin@foobar.com>'
    to :recipient
    subject :subject

    def prepare
      Hanami.logger.debug "Start #{__method__} in #{self.class.inspect} #{self.object_id} :
        tempfile: #{tempfile.path} size: #{tempfile.size  }\n
        client_contact_email: #{client_contact_email.pretty_inspect}\n
        test_mail: #{test_mail.pretty_inspect}\n
        mail: #{mail.pretty_inspect}"

      Hanami.logger.debug "During #{__method__} in #{self.class.inspect} #{self.object_id} :

      mail.attachments['invoice.pdf'] = tempfile.open.read
      # from https://www.rubydoc.info/gems/hanami-mailer#Attachments

      Hanami.logger.debug "End #{__method__} in #{self.class.inspect} #{self.object_id} :
        mail: #{mail.attachments.pretty_inspect}"
    end

    private

    def recipient
      if test_mail
        'admin@foobar.com'
      else
        client_contact_email
      end
    end

    def subject
      'Invoice for service'
    end

  end
end

The mailer is called from a non-crud controller that prepares the context and locals, the pdf is generated by an interactor.

what i'm expecting the email to be structured like:

multipart/mixed
  multipart/alternative
    text/plain
    text/html
  application/pdf (i.e. in case of pdf attachment)

what i'm receiving:

multipart/alternative
  text/plain
  text/html
  application/pdf (i.e. in case of pdf attachment)

the practical effect:
thunderbird renders the right text body, depending on user preference (txt or html), but does not show the attachment as an attached file (it is however in the email source code as a bas63-encoded block)
ios mail shows an empty email body, and only the pdf attachment as a file, since it is the last entry, and apparently the mail client then only renders this.

for reference some issues about this from the Mail gem:
mikel/mail#853
mikel/mail#1022
mikel/mail#862
mikel/mail#590

here's a gist that prevents this from happening when using the gem only:
https://gist.github.com/steve500002/bfc4b027d93c0c04f126

any other detail needed?

@whysthatso
Copy link
Author

i'm a bit confused as if i really do the right thing, because i presume that this would have been come up earlier, as it's a pretty common use case of emailing.

@mereghost mereghost self-assigned this Jul 19, 2019
@whysthatso
Copy link
Author

@mereghost lmk if i can provide any more info or testing

@mereghost
Copy link
Member

Heya folks,

The issue seems to exist upstream as we use mail under the hood. So I was actually trying to deal with it there without breaking too much stuff, taking all the advice from all those tickets.

@whysthatso
Copy link
Author

i see, would you be able to link to an issue there, wherever they keep their repo, to follow it directly along the source?

@mereghost
Copy link
Member

This issue is already kinda linked there as you mentioned mikel/mail#1022 here. =)

If I manage to fix this, for sure I'd mention both issues. =)

@whysthatso
Copy link
Author

ah right, sorry, i forgot i had looked into this back then as well :D
fair enough. and thank you for taking this on a bit 👍

@hoxia
Copy link

hoxia commented Mar 20, 2020

Just FYI, I reported a similar bug against Discourse, where I linked and quoted this bug report. Discourse fixed their similar bug by changing how they call the mail gem. It seems that's the typical course with similar bugs. discourse/discourse@59578df

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