使用自定义SMTP设置发送电子邮件

时间:2017-08-16 11:54:46

标签: ruby-on-rails email

我想使用通过某些网络表单提供的凭据通过SMTP从rails发送电子邮件。因此,而不是在启动时使用以下内容配置邮件程序:

ActionMailer::Base.smtp_settings = {
  :address              => address,
  :domain               => domain,
  :user_name            => user_name,
  :password             => password,
}

然后使用UserMailer.send_mail(user).deliver_now

发送邮件

我想根据从数据库中获取的变量,仅为一个邮件设置smtp设置。

是否可以使用rails实现此行为?

1 个答案:

答案 0 :(得分:0)

class UserMailer < ApplicationMailer
  self.smtp_settings = {
  :address => ‘smtp.gmail.com’, :port => 587,
  :domain => ‘gmail.com’,
  :authentication => ‘plain’,
  :user_name => <email_username>,
  :password => <email_password>,
  :enable_starttls_auto => true
  }

 send_mail(option, data) 

     email.delivery_method.settings.merge!({:address => 
     Email.email_address, :port => Email.email_port, :domain => 
     Email.email_domain, :user_name =>Email.email_username, :password => Email.email_password, :enable_starttls_auto => true}) 
     email.deliver_now 
 end

end

尝试类似

的内容