UP 04/08/2015: 実際に.deliver_later
と proc の両方を使用することは可能ですか?
私の問題 :
私の電子メールは TO フィールドを生成する手順を実行しないため、postfix で不適切な電子メールが送信されます
後置ログ
sudo tail -n 150 /var/log/mail.log
Jul 30 17:39:44 je postfix/pickup[3974]: 0DA531FC2AFA: uid=1030 from=<candidature@myorg.com>
Jul 30 17:39:44 je postfix/cleanup[8430]: 0DA531FC2AFA: message-id=<55ba453fc4fd1_20e02375a9c04882a@myorg.mail>
Jul 30 17:39:44 je postfix/qmgr[3506]: 0DA531FC2AFA: from=<candidature@telecom-etude.com>, size=18915, nrcpt=2 (queue active)
Jul 30 17:39:44 je postfix/error[8522]: 0DA531FC2AFA: to=<Proc:0xbbd2989c@/var/www/intranet_rails_production/releases/20150729170507/app/mailers/mailing_lists_mailer.rb:42>, relay=none, delay=0.41, delays=0.22/0.02/0/0.17, dsn=5.1.3, status=bounced (bad address syntax)
Jul 30 17:39:44 je postfix/error[8522]: 0DA531FC2AFA: to=<#<Proc:0xbbd2989c@/var/www/intranet_rails_production/releases/20150729170507/app/mailers/mailing_lists_mailer.rb:42>>, relay=none, delay=0.52, delays=0.22/0.02/0/0.28, dsn=5.1.3, status=bounced (bad address syntax)
コントローラ
...
if Rails.env.production? # Using :sendmail as delivery method
MailingListsMailer.action(@mail).deliver_later
else # Typically using :letter_opener or :file as delivery method
MailingListsMailer.action(@mail).deliver_now
...
メーラー
class MailingListsMailer < ActionMailer::Base
def action(message)
format_mail_params(message)
mail(
to: Proc.new {read_emails_file},
...
)
end
private
def read_emails_file
File.read('emails.txt').split('\n')
end
end
設定
config.action_mailer.delivery_method = :sendmail
config.action_mailer.smtp_settings = {
:address => "localhost",
:domain => "myorg.fr"
}
config.action_mailer.default_url_options = { host: 'myorg.fr', protocol: 'https' }
EDIT: ActionMailer Basics#2.3.3で提案されているようにprocを使用していました