gpt4 book ai didi

ruby-on-rails - Rails 邮件程序 : change file when delivery_method :file

转载 作者:行者123 更新时间:2023-11-28 20:12:11 24 4
gpt4 key购买 nike

我想要文件名为 Timestamp + normal_mail_name + ".eml"..

我查看了 rails 源代码、mail-gem 源代码和 letter opener-gem.. 你能给我一个提示如何(monkey-patch)rails 邮件程序以支持我可以指定如下内容:

config.action_mailer.file_settings = { :location => Rails.root.join('tmp', 'mail'), :file_name => Time.now.to_i.to_s + "mail.eml"}

谢谢!

更新:如果能用我本地关联的带有启动功能的电子邮件程序自动打开这些邮件也很好,比如开信器 gem..我会自己做,但我不明白源代码..

最佳答案

我想你有很多邮件程序的东西,你会想要调试邮件正文、文本等?我对吗?如果我是对的,我不会使用 delivery_method :file 发送邮件,我只是创建一个真实的电子邮件(例如 gmail)帐户并通过测试帐户发送邮件。

例如在你的 config/environments/development.rb 中:

email_settings = YAML::load(File.open("#{Rails.root.to_s}/config/mail.yml"))[Rails.env] rescue nil

if email_settings.nil?
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_deliveries = false
config.action_mailer.delivery_method = :file
else
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "#{email_settings["address"]}",
:port => email_settings["port"],
:authentication => "#{email_settings["authentication"]}",
:user_name => "#{email_settings["user_name"]}",
:password => "#{email_settings["password"]}",
:enable_starttls_auto => email_settings["enable_starttls_auto"]
}
end

还有你的 mail.yml 文件:

development:
address: smtp.gmail.com
port: 587
authentication: login
user_name: test@your-domain.com
password: yourpassword
enable_starttls_auto: true

这并不是您问题的真正直接答案,但也许这种解决方法对您来说是个不错的选择。您还可以根据需要以相同的方式配置其他环境。

关于ruby-on-rails - Rails 邮件程序 : change file when delivery_method :file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16154872/

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