2009-12-18 99 views
12
發展中通過的ActionMailer 實際上發送

我有問題,在我的本地,與線路2.3.2的Ruby 1.8.6。 development.log顯示它發送了沒有錯誤的電子郵件,但沒有收到電子郵件。我嘗試了多個電子郵件地址進行發送和接收,並嘗試了多個配置和插件,但無法發送電子郵件。任何幫助將不勝感激 - 我覺得我正在圍繞着不同版本的rails和ruby的一系列解決方案跳舞,並且無法完成它。我非常感謝任何評論。謝謝!的ActionMailer郵件「發送」,但沒有收到

插件:

  • 行動郵件可選TLS
  • smtp_tls

不同的電子郵件CONFIGS:

ActionMailer::Base.smtp_settings = { 
    :enable_starttls_auto => true, #works in ruby 1.8.7 and above 
    :address => 'smtp.gmail.com', 
    :port => 587, 
    :domain => 'example.com', 
    :authentication => :plain, 
    :user_name => 'testacct', 
    :password => 'secret' 
    } 

config.action_mailer.delivery_method = :smtp 
    config.action_mailer.smtp_settings = { 
    :tls => :true, 
    :address => 'smtp.gmail.com', 
    :port => 587, 
    :authentication => :plain, 
    :user_name => '[email protected]', 
    :password => 'secret' 
    #:enable_starttls_auto => true # for rails >= 2.2 && ruby >= 1.8.7 
    } 
    config.action_mailer.perform_deliveries = :true #try to force sending in development 
    config.action_mailer.raise_delivery_errors = :true 
    config.action_mailer.default_charset = "utf-8" 

Development.log:

Sent mail to [email protected] 

Date: Fri, 18 Dec 2009 00:27:06 -0800 
From: Test Email Acct <[email protected]> 
To: [email protected] 
Subject: Signup 
Mime-Version: 1.0 
Content-Type: multipart/alternative; boundary=mimepart_4b2b3cda9088_634334302a5b7 


--mimepart_4b2b3cda9088_634334302a5b7 
Content-Type: text/html; charset=utf-8 
Content-Transfer-Encoding: Quoted-printable 
Content-Disposition: inline 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww= 
w.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html lang=3D'en' xml:lang=3D'en' xmlns=3D'http://www.w3.org/1999/xhtml'>= 

    <head> 
    <meta content=3D'text/html;charset=3DUTF-8' http-equiv=3D'content-typ= 
e' /> 
    </head> 
    <body> 
    Welcome Email 
    <p> 
     user name: 
     lfglkdfgklsdf 
     activation link: 
     http://localhost:3000/login 
    </p> 
    </body> 
</html> 

--mimepart_4b2b3cda9088_634334302a5b7-- 
+0

檢查那些被標記爲垃圾郵件。 – Waseem 2009-12-18 11:09:11

+0

沒有。不是垃圾郵件。 – user117046 2009-12-18 22:36:40

+0

謝謝你們,不知道發生了什麼事情(或許與smtp服務器有關),但它今天的作品具有相同的確切代碼。 GUH。 – user117046 2009-12-18 22:38:57

回答

8

您需要使用true而不是:true

:tls => true 
... 
config.action_mailer.perform_deliveries = true #try to force sending in development 
config.action_mailer.raise_delivery_errors = true 
+0

不確定,但它們可以互換嗎?我也嘗試使用「true」而不是「:true」。 – user117046 2009-12-18 22:38:18

+2

它們可能是可以互換的,因爲圖書館可能只是檢查它們是否不是'零'而不是'假'。 – henrikhodne 2009-12-19 10:26:23

4

在任何情況下,面臨的這個問題,在development.rb在您的環境中的文件夾設置爲「config.action_mailer.raise_delivery_errors = true」,並再次嘗試發送郵件。這應該會引發遇到的任何錯誤。

有時在smtp_tls.rb的第8行中,check_auth_args方法只接受2個參數:user和secret。如果看到它,請刪除'authtype'參數並重試。應該管用。

+0

偉大的提示!另外值得注意的是,如果你在其他地方指定了你的配置的某些部分,例如。使用[dotenv](https://github.com/bkeepers/dotenv),我強烈建議,請確保您包裝可能包含特殊字符的任何值在單引號中。 – schmielson 2013-12-12 18:23:30

12

放入config/environments/development.rb

config.action_mailer.perform_deliveries = true 
config.action_mailer.raise_delivery_errors = true 

下它會覆蓋設置在config/environment.rb

也爲2.X,您需要安裝導軌:

config.action_mailer.delivery_method = :smtp 
config.action_mailer.smtp_settings = { 
    :enable_starttls_auto => true, 
    :address  => "smtp.gmail.com", 
    :port   => 587, 
    :domain   => "domain.com", 
    :user_name  => "[email protected]", 
    :password  => "secret_passsword", 
    :authentication => :plain 
} 
+2

感謝您提供關於'raise_delivery_errors = true'的提示。這幫助我更接近地識別錯誤,這是我只將「** name **」部分放在'user_name'的值中,而不是完整的電子郵件地址「**[email protected]**」 。把完整的電子郵件地址,電子郵件發送!注:我沒有*需要設置'perform_deliveries = true'。我現在正在運行Rails 3.1.0。 – user664833 2012-04-17 21:14:55

+0

所以我有這個完全相同的問題。不,它不是垃圾郵件,是的,郵件確認發送,是的,我也提高了交付錯誤,並將交付設置爲true。我們是否確定它最終神奇地工作?這裏沒有明確的答案... – fresh5447 2014-12-02 22:29:56

相關問題