我是Pony的新手。在我的sinatra应用程序中,我使用Pony发送邮件。但我面临的问题是发送多个csv文件作为附件。在邮件中,我只获得一个文件noname.csv,其中包含所有文件的内容。但我不想要它,我希望所有文件都单独附加。我编写的代码如下:
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
答案 0 :(得分:1)
我遇到了同样的问题,我通过在电子邮件中添加一个空体来解决它。字面上...
:body => '',
这是我的全部调用:
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"),
}
})