2008-10-28 143 views
2

所以我action_mailer_optional_tls(http://svn.douglasfshearer.com/rails/plugins/action_mailer_optional_tls) ,這在我的enviroment.rb通過Gmail發送電子郵件來自不同帳戶

ActionMailer::Base.server_settings = { 
    :tls => true, 
    :address => "smtp.gmail.com", 
    :port => "587", 
    :domain => "www.somedomain.com", 
    :authentication => :plain, 
    :user_name => "someusername", 
    :password => "somepassword" 
} 

但現在什麼?如果我想從不同的電子郵件帳戶發送電子郵件? 如何隨時覆蓋user_name和密碼字段?

我在尋找的是一個解決方案,允許帳戶之間的動態切換。示例以下情形: 10「管理員」可以向我們的客戶發送通知。每個人都有自己的Gmail帳戶,當他們填寫表格時,使用他們的帳戶軌道連接併發送郵件。

在此先感謝!

阿里

回答

0

如果你想使用不同的電子郵件地址從目標接收器的答覆, 您可以指定回覆:[email protected] SMTP協議的,仍然使用現有帳號谷歌smtp服務。

但是,您需要轉到Gmail設置才能將[email protected]添加到「將電子郵件發送爲」列表中,這還需要您通過發送指向該收件箱的鏈接來確認[email protected]是否屬於您。

1

我無法驗證它現在可以正常工作,但您應該嘗試只是即時修改這些設置。即在發送電子郵件之前立即從用戶帳戶設置用戶名/密碼。你甚至可以在控制器上設置一個過濾器來加載該信息。

before_filter :load_email_settings 

def load_email_settings 
    ActionMailer::Base.server_settings.merge!(:user_name => current_user.email, :password => current_user.email_password) 
end 

def current_user 
    @current_user ||= User.find(session[:user_id]) 
end 

注意,存儲用戶的電子郵件密碼以明文形式是非常危險的,我不知道是否有什麼辦法可以做你想要使用的是什麼谷歌帳戶的third party authentication計劃,但你可能要檢查了這一點。

0

從Rails 2.3起,不需要插件action_mailer_optional_tls。相反,你應該把下面的你environment.rb

config.action_mailer.delivery_method = :smtp 
config.action_mailer.smtp_settings = { 
    :enable_starttls_auto => :true, 
    :address => "smtp.gmail.com", 
    :port => 587, 
    :domain => "mydomain.example.com", 
    :authentication => :plain, 
    :user_name => "[email protected]", 
    :password => "xxxxxxx", 
    :tls => :true 
} 
config.action_mailer.perform_deliveries = :true 
config.action_mailer.raise_delivery_errors = :true 
config.action_mailer.default_charset = "utf-8" 
+0

答案是由伊萬評論在http://douglasfshearer.com/blog/gmail-smtp-with-ruby-on-rails-and複製-actionmailer – 2009-10-14 07:05:19

相關問題