2014-03-26 13 views
1

포니를 처음 사용합니다. 내 sinatra 응용 프로그램에서 나는 포니를 사용하여 메일을 보내고 있습니다. 하지만 첨부 파일로 여러 csv 파일을 보내는 문제가 있습니다. 메일에서 모든 파일의 내용과 함께 하나의 파일 noname.csv 만 표시됩니다. 하지만 나는 그것을 원하지 않는다, 나는 모든 파일이 따로 따로 첨부되기를 바란다. 나는이 동일한 문제로 실행하고 나는 이메일에 빈 몸을 추가하여 해결포니에 여러 개의 CSV 파일을 첨부합니다.

def send_mail(file1, file2) do 
    Pony.mail(
    :from => "[email protected]", 
    :to => "[email protected]", 
    :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 
+0

는'추가 : headers'를 [이 질문] 두 번째 대답 (http://stackoverflow.com/questions/5160751 같이 그대로 ...

:body => '', 

여기 내 전체 호출했다/with-pony-gem의 첨부 파일로 이메일 보내기)를 사용하면 결과를 향상시킬 수 있습니다. – Patru

+0

나는 이미 그렇게했다. – Joy

답변

1

다음과 같이 나는 코드를 작성했습니다.

Pony.mail({ 
    :to => '[email protected]', 
    :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"), 
    } 
})