我正在使用actionmailer在轨道中发送邮件。我想附加多个附件:
def prepare_attachments(languages)
attachments = {}
languages.each do |language|
next unless language.document
attachments[language.document.filename] = language.document.read
end
return attachments
end
def distribution_email(recipient, languages)
attachments = self.prepare_attachments(languages)
mail(
:to => recipient,
:subject => 'Test'
)
end
已送达的邮件不包含任何附件。这是有效的:
def distribution_email(recipient, languages)
attachments['test.pdf'] = File.read("/tmp/test.pdf")
mail(
:to => recipient,
:subject => 'Welcome to My Awesome Site'
)
end
我做错了什么?
我支持解决方案,不能覆盖附件:
def prepare_attachments(languages)
attachments = {}
languages.each do |language|
next unless language.document
attachments[language.document.filename] = language.document.read
end
return attachments
end
def distribution_email(recipient, languages)
self.prepare_attachments(languages).each do |filename, content|
attachments[filename] = content
end
mail(
:to => recipient,
:subject => 'Test'
)
end