我正在尝试从Rails AWS EB应用程序(工作层)发送带有CSV附件的电子邮件。
此示例将使用附加的数据正确发送电子邮件,我已在此处对CSV字符串进行了硬编码;
def send_mail
content = "Example,CSV,Content\n,..."
attachments['test.csv'] = { mine_type: 'text/csv', content: content}
mail( :from => 'test@mail.com>',
:to => 'person@mail.com',
:subject => 'Email with attachment',
:body => "testing sending email attachment"
)
end
然而,当我从API发送CSV字符串时,我似乎遇到了编码问题。我发送的对象是这个;
email = {
from: "test@mail.com",
to: "person@mail.com",
subject: "Email with attachment",
content_type: 'text/html',
attachments: {
filename: 'test.csv',
content: File.read("#{Rails.root}/test.csv")
}
}
方法;
def send_mail(params)
filename = params[:attachments][:filename]
attachments[filename] = { mine_type: 'text/csv',
content_type: 'text/comma-separated-values',
transfer_encoding: '7bit',
content: [:attachments][:content]
}
mail(params)
end
我认为 transfer_encoding 可能存在问题,如果我没有将其设置为' 7bit'内容是base64加密的。我已经使用了动作邮件程序方法 attachments.instance_values 来检查有效的电子邮件的content_encoding及其二进制文件,但是我在故障示例中将其设置为二进制文件,它将恢复为base64。如果我将params [:attachments] [:content]设置为变量,那么当我记录attachments.instance_values时,值为' binary'但是当收到邮件时,邮件是;
----==_mimepart_57ac6ae25a220_68972ad836f669fc984a7
Content-Type: text/comma-separated-values; charset=UTF-8
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=test.csv
mine-type: text/csv
Content-ID: <57ac6ae259b90_68972ad836f669fc983b0>
任何帮助或建议表示赞赏。
答案 0 :(得分:1)
它应该是mime-type,而不是我的类型才能正确解析。