1

Rubys ActionMailer を使用して添付ファイルを送信しようとしています。しかし、ファイルを送信すると、追加した改行「\r」が削除されます。

string = "the quick brown\r\nfox jumped over\r\nthe bridge"

File.open(file = "attachment_#{Time.now.to_i}.txt", "w+") do |f|
  f.write(string)
end

attachments['test_file.txt'] = {
  mime_type: 'text/plain',
  content: string
}

mail(
  :to => 'somebody@example.com',
  :from => 'somebody@example.com',
  :subject => 'Message Test'
).deliver

書き込まれたファイルには適切な行末がありますが、添付ファイルにはキャリッジ リターンが削除されています。どうすればこれを防ぐことができますか?

4

1 に答える 1