我不确定为什么我通过ActionMailer发送的带有附件的电子邮件不显示附件,而是将附件的内容显示/输出到电子邮件中。
class MyMailer < ActionMailer::Base
default :from => "email@email.com"
def test_email()
attachments['testresult1.html'] = {
:filename => 'testresult1.html',
:body => File.read('C:\\testresult1.html')
}
mail(:to => 'email@email.com',
:subject => 'Cool great message'
)
end
end
电子邮件的输出如下所示
Date: Tue, 17 Apr 2012 14:11:52 +1000
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8;
filename=testresult1.html
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename=testresult1.html
filename: testresult1.html
Content-ID: <4f8ced883c0d9_1b1c30b580813e@PC-049.mail>
然后是HTML文件/附件的全部内容。
我希望HTML文件会附加到电子邮件中,就像它会附加到普通电子邮件中一样,并且我应该能够双击附件并在浏览器中打开它。
Email Client = Microsoft Outlook
Connection = SMTP
Rails = 3.2.1
ActionMailer = 3.2.1
Mail = 2.4.4
发布于 2012-04-17 05:57:25
您应该尝试在# body
中添加一个邮件密钥。
发布于 2012-06-02 14:37:32
非常感谢Philip :)
我发送了一个没有任何正文属性的附件,我遇到了以下两个问题:
当"noname"
但是在邮件中添加了正文属性之后,它就可以工作了。
因此,正确的语法是:
attachments['mypdf.pdf'] = File.read('#{Rails.root.to_s}/public/test.pdf')
mail(:to => guru****@gmail.com, :from => guru****@gmail.com, :subject => 'Attachment Test Mail', :body => 'Regards, Guru')
发布于 2012-10-10 10:27:15
我也有同样的问题,因为'Noname‘和corrupted。
我使用的代码如下:
attachments['126539_statistics.pdf'] = File.read("app/assets/pdfs/126539_statistics.pdf")
mail(:to => email, :subject => subject, :body => message)
发送带有附件的邮件没有任何问题...
https://stackoverflow.com/questions/10185850
复制相似问题