我正在尝试使用ruby on rails发送带有附件的电子邮件。
我遵循了the ActionMailer网站的指示。
def welcome(recipient)
@account = recipient
attachments['file.csv'] = File.read('/path/to/users.csv')
mail(:to => recipient,
:bcc => ["email@example.com", "email2@example.com"],
:subject => "Sending attachment")
end
我可以接收电子邮件,但没有附件,我试图附加csv文件,但我得到一个名为“noname”的文件作为附件
最佳答案
我刚遇到这个问题。我没有提供电子邮件的正文,只是发送附件不幸的是,SendGrid似乎对此感到困惑,发送一封空邮件(这是预期的)和一个空附件(这既不是预期的也不是预期的)。
因此,解决方案是:为电子邮件提供正文在您的特定情况下,一个带有简单文本的/app/views/application_mailer/welcome.text.erb
模板,上面写着“See attached”或任何适当的内容。