gpt4 book ai didi

ruby-on-rails - 将远程 URL 文件附加为操作邮件程序中的附件

转载 作者:行者123 更新时间:2023-12-02 13:40:23 25 4
gpt4 key购买 nike

我有一个 ActionMailer 设置来从 S3 发送带有附件的电子邮件。我这样做是这样的:

def job_apply(current_tenant, applicant)
@current_tenant = current_tenant
@applicant = applicant

file = open(applicant.resume.url).read
attachments[applicant.resume] = file

email_with_name = "#{@current_tenant.name} <#{@current_tenant.help_email}>"
mail(from: email_with_name, to: applicant.job.apply_email, subject: "New Job Application")
end

applicant.resume.url 返回一个正确的 URL,我可以在浏览器中打开它并检索文件,但是我收到以下错误:

Message undefined method `ascii_only?' for #<ApplicantResumeUploader:0x007fe6bc5c28a8>
File /Users/cmalpeli/.rvm/gems/ruby-1.9.3-p194@job_board/gems/mail-2.4.4/lib/mail/encodings.rb
Line 103

这是encodings.rb中的代码:

 98     def Encodings.decode_encode(str, output_type)
99 case
100 when output_type == :decode
101 Encodings.value_decode(str)
102 else
103 if str.ascii_only?
104 str
105 else
106 Encodings.b_value_encode(str, find_encoding(str))
107 end
108 end

我有点不知所措......

如有任何帮助,我们将不胜感激...

最佳答案

问题出在 attachments[applicant.resume] 中的 applicant.resume 字符串。如果这不是一个字符串(如 JavaScript 对象),也不是一个可以代表您要附加到电子邮件的文件的文件名,那么这将导致 ActionMailer 出现问题。

在继续之前,请验证 applicant.resume 字符串确实是 foo.pdfresume.doc 等文件名。

关于ruby-on-rails - 将远程 URL 文件附加为操作邮件程序中的附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13792220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com