【发布时间】:2018-11-09 05:55:36
【问题描述】:
我需要发送带有附件的简单邮件。现在它发送一封电子邮件,但附件是这样的电子邮件正文。
--
Content-Type: text/csv;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename=errors_in_address_table.csv
Content-ID: <5b0e7d6b4abff_10c12ac224c8b0d4994d@development.mail>
发送电子邮件的当前代码
saved_file = Rails.root.join('db', 'fix_db', 'errors_in_address_table.csv')
mailer = ActionMailer::Base.mail(from: 'no-replay@test.com', to: 'test@test.com', subject: 'Errors in database', body: '', content_type: 'multipart/mixed')
mailer.attachments['errors_in_address_table.csv'] = { mime_type: 'text/csv', content: File.read(saved_file) }
mailer.deliver
我试图让它正常工作几个小时。也许一些更有经验的程序员可以帮助我。
【问题讨论】:
-
我不知道你所说的“在电子邮件正文中”是什么意思,也许因为你的邮件客户端显示它以某种方式内联而令人困惑?但从 EML 我可以说它是作为附件存储的
-
@siegy22 发送邮件后,我在正文部分收到了包含此文本的电子邮件。
-
你能上传你的电子邮件吗? .eml 文件?
标签: ruby-on-rails ruby email sendmail ruby-on-rails-4.2