I have a script that generates a sql dump. I am trying to automate this further so it sends out an email with gzipped attachment. All works apart from when I receive the email it returns the following:
-- Content-Type: application/x-gzip; charset=UTF-8 Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=company_dump.gz Content-ID: <551979ffcf8d6_239f11b2ff074555@home-System-Product-Name.mail> H4sICN1PGVUAAy4uL2NvbXBhbnlfZXh0cmFjdF9kdW1wLnNxbADsvft22zi2 8Pn31FPgq/nDqfPFadwvOtOz2rfEqThOynba3WdqlouSKJsdiXRTUlzus3qt 7zW+15snGYAXCSQhiTJ1cTmqqk7HMEmAxP7tvQFsbOzvg4+Pl7+cge54cA8Q fIMIAMfBcBQHbcDesDdEvga9KAZdvx144X4/CMe/79+GY/Dqd8lvOP3ph/19 /R84jYajFuhHHa9/p/8K9D/H3shre0O/BcZfb9rt8a25bv9J/5g7L/34mx8D /b9hEIX/R9q4fThuj8PRWDccv4H0Dfrhhz/9x/+gEEEELk+uwF8+nR3fHJ0e XBwcXZ1c3Oiim6Oz9yfnV3/+y19cxeA//vSfC59wcXL55ezqsvKIrHzWMz6d nR1cvf90rv92fn5yZP5qHuEorj7h/ODjySUYj3rS/h2ZPv3q/ceTm//6dH6i Hzn5e/Xa6WV7/xPCFoR702sgotPnfTl//8uXE/3iJ0cfzJsWfn4Nir+GMx7y 9tPFyft35zcfTv4+fVK18DVwXAhnfEYtrDcfPx2b98z/+hpMCvfOP90cfLn6 dPPXgzPdPv1V/+vk4pP1kgiVnnX+6erkMntY8vf0aWlx2ohMxK+8dt8HGo1x ZzSO/QSLUVL2m9f17kfBN//m3nsc+OHoRmPQb3udr8PfzM0/HF98+gyuDg7P TsD7t+Dkb+8vtZjMu6v85kPvm9+96QxvOv1AX2nwAn8Gf/lL586Lvc7Ij2+G /ij/ZeXDOa/681Scji5ODq5OsgbOaxZ49QMAvwXd30AQjl4h9BPQ3wmcfzk7
My supported code is below:
class Notifier < ActionMailer::Base
def company_extract_email(file)
recipients = 'Internal <internal@some_domain.com>'
from = 'noreply@some_domain.com'
subject = 'See attached'
message = mail(:to => recipients, :from => from, :subject => subject, :reply_to => reply_to) do |format|
format.html { render :text => 'See the attached'}
end
attachments['company_dump.gz'] = {mime_type: 'application/x-gzip', content: File.read("#{file}.gz")}
reply_to = 'noreply@some_domain.com'
end
end
The following is called from within a script I've written:
def export_mysql(company, company_name)
extend ActionView::Helpers
conf = ActiveRecord::Base.connection_config
filename = "company_extract_dump"
file = "../#{filename}"
system("mysqldump -P 3306 -h #{conf[:host]} -u #{conf[:username]} -p #{conf[:database]} > #{file}.sql")
Zlib::GzipWriter.open("#{file}.gz") do |gz|
gz.orig_name = "#{file}.sql"
gz.write IO.binread("#{file}.sql")
end
size = number_to_human_size(File.size("#{file}.gz"), precision: 2)
if size < number_to_human_size(2.6e+7, precision: 2)
email = Notifier.company_extract_email(file)
email.deliver if email
end
File.delete("#{file}.sql")
File.delete("#{file}.gz")
end
I also did come across: ActionMailer 2.3.5 mangles my zip attachment. I have tried setting the content_transfer_encoding: "base64"
but this does not make a difference.
Aucun commentaire:
Enregistrer un commentaire