2011-06-03 71 views
2

我想從我的Ruby on Rails應用程序中通過Gmail發送的電子郵件來自Ben爲什麼我不能在我的Rails應用程序中使用Gmail正確設置FROM名稱?

目前,當電子郵件到達一個(單獨的,無關的)Gmail帳戶時,在收件箱中它的起始部分有ben

這裏是我的設置:

爲setup_mail.rb

# my domain is my_example.com, and the email address I am sending from is [email protected]_example.com 
ActionMailer::Base.smtp_settings = { 
    :address    => "smtp.gmail.com", 
    :port     => 587, 
    :domain    => "my_example.com", 
    :user_name   => "[email protected]_example.com", 
    :password    => "my_password", 
    :authentication  => "plain", 
    :enable_starttls_auto => true 
} 
if Rails.env.development? 
    ActionMailer::Base.default_url_options[:host] = "localhost:3000" 
else  
    ActionMailer::Base.default_url_options[:host] = "my_example.com" 
end 

report_mailer.rb

def send_notification_email(notification_details) 
    subject = "testing_email" 
    mail(:to => notification_details[:email], :subject => subject, :from => "Ben") 
    end 

這裏是在Gmail電子郵件設置: enter image description here

回答

4

在:從部分實際上你可以指定的電子郵件地址是這樣的:

:from => 'Ben <[email protected]_example.com>' 
+0

非常感謝您的幫助! – ben 2011-06-19 03:20:06

+0

很高興幫助:) – 2011-06-19 06:05:16

+0

如果你使用的是devise,那麼你可以在'config/initializers/devise.rb'中設置from字段,如下所示:'config.mailer_sender =「\」Awesome Name \「「' – Automatico 2015-05-29 01:33:36

2

:from關鍵在於其實您發送的電子郵件。 GMail不允許重寫,因爲它可能導致濫用。

+0

但它從哪兒得到的「奔」的一部分?這就是在Gmail收件箱的「發件人」部分中顯示的內容(我已將其編輯到問題中)。 – ben 2011-06-03 08:52:47

+0

從您的Gmail帳戶轉到設置 - >帳戶。有一個字段發送電子郵件爲:最有可能它設置爲本地 – 2011-06-03 10:39:01

+0

我認爲這就是我包含的截圖是什麼?還有其他地方嗎? – ben 2011-06-04 01:39:52

相關問題