我需要发送带有附件的简单邮件。目前它可以发送邮件,但是附件在邮件正文中,就像这样。
![enter image description here](https://istack.dev59.com/Kt8q3.webp)
--
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
我花了几个小时来尝试使这个工作正常。也许一些更有经验的编码人员可以帮我。