dimanche 10 avril 2016

Switching from Postmark to Postfix

We want to switch from Postmark to Postfix, but with postfix the mail with the attachment(pdf file) is arriving as garbage:

" -- Date: Sun, 10 Apr 2016 13:17:56 +0300 Mime-Version: 1.0 Content-Type: application/pdf; charset=UTF-8; filename=test_order1460278254278.pdf Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=test_order1460278254278.pdf Content-ID: <570a2854317a9_1c6f12f77f841854@app1.mail> JVBERi0xLjQKJeLjz9MKNSAwIG9iago8PC9CYXNlRm9udC9QV1dNR1QrQXJp YWxNVC9EZXNjZW5kYW50Rm9udHNbNiAwIFJdL1R5cGUvRm9udC9TdWJ0eXBl L1R5cGUwL0VuY29kaW5nL0lkZW50aXR5LUgvVG9Vbmljb2RlIDkgMCBSPj4K ZW5kb2JqCjEwIDAgb2JqCjw8L0Jhc2VGb250L1dYSkRSSytMdWNpZGFTYW5z LVR5cGV3cml0ZXJCb2xkL0Rlc2NlbmRhbnRGb250c1sxMSAwIFJdL1R5cGUv Rm9udC9TdWJ0eXBlL1R5cGUwL0VuY29kaW5nL0lkZW50aXR5LUgvVG9Vbmlj b2RlIDE0IDAgUj4+CmVuZG9iagoxNSAwIG9iago8PC9CYXNlRm9udC9UaW1l "

This is my code:

    class UserMailer < ActionMailer::Base
      default :from => "mailer@xodapp1.com"
      default :bcc => "do_not_reply@xodapp1.com"
      default :reply_to => "do_not_reply@xodapp1.com"

      def send_email(agent, customer, subject, body, mail_to = nil, mail_cc = nil, url_attachment = nil , name_attachment = nil)
        #attachments[name_attachment] = {:content => open(url_attachment).read, :mime_type =>  MIME::Types.type_for(name_attachment).first}  unless url_attachment.nil?
        mail_to = !mail_to.nil? ?  mail_to : "\"#{customer.name}\" <#{customer.email}>"
        mailers_to = mail_to.split(',')

        mail_cc = !mail_cc.nil? ?  mail_cc.split(',') : agent.email
        if [nil, []].include?(mail_cc)
          mail_cc = UserMailer.default[:bcc]
        end

        body = "Copy attached" if body.nil? || body.empty?

        mail_obj = mail(:to => mailers_to,
             :from => "\"#{agent.name}\" <mailer@xodapp1.com>",
             :bcc =>  mail_cc,
             :subject => subject,
             :content_type => "text/html",
             :body => body.html_safe,
             :reply_to => "#{!agent.email.nil? ? agent.email : UserMailer.default[:reply_to]}"
        )
        mail_obj.attachments[name_attachment] =  open(url_attachment).read unless url_attachment.nil?
        return mail_obj
      end
end

Thanks in advance

Adrian

Aucun commentaire:

Enregistrer un commentaire