1

I am new to Pony. In my sinatra application I am sending mail by using Pony. But the problem I am facing with sending multiple csv files as attachments. In mail I am getting only one file noname.csv with content of all the files. But I don't want it, I want all the files comes attached separately. I have written the code as follows:

def send_mail(file1, file2) do
  Pony.mail(
  :from => "mailer@abc.com",
  :to => "joy@abc.com",
  :subject => "text",
  :content_type => "text/csv",
  :via => :smtp,
  :via_options => {
  :address => "abc.com", 
  :port => 587,
  :user_name => "test",
  :password => "test123",
  :authentication => plain ,
  :domain => "abc.com",
  :enable_starttls_auto => true},
  :attachments => {"a.csv" => File.read("#{settings.root}"+"/"+"#{file1}"),"b.csv"=>File.read("#{settings.root}"+"/"+"#{file2}")} 
end 
xdazz
  • 158,678
  • 38
  • 247
  • 274
Joy
  • 4,197
  • 14
  • 61
  • 131
  • Adding `:headers` as in the second answer to [this question](http://stackoverflow.com/questions/5160751/sending-email-with-attachments-in-ruby-with-the-pony-gem) might improve your outcome. – Patru Mar 26 '14 at 08:00

1 Answers1

1

I ran into this exact same problem and I solved it by adding an empty body to the email. Literally...

:body => '',

Here was my full invocation:

Pony.mail({
  :to => 'me@domain.com',
  :via => :smtp,
  :body => '',
  :via_options => {
    :address              => 'smtp.gmail.com',
    :port                 => '587',
    :enable_starttls_auto => true,
    :user_name            => '<username>',
    :password             => '<application specific password>',
    :authentication       => :plain
  },
  :subject => 'test email',
  :attachments => {
    "file.csv" => File.read("/tmp/test_file.csv"),
    "file2.xls" => File.read("/tmp/test_file.xls"),
  }
})
Richard Nienaber
  • 10,324
  • 6
  • 55
  • 66