2013-04-26 114 views
0

我無法從本地主機發送郵件。這是我的代碼。 起初我是生成郵件用戶郵箱。 enviroment.rb:Ruby On Rails.How send email?

config.action_mailer.delivery_method = :smtp 

config.action_mailer.smtp_settings = { 
:adress => '[email protected]', 
:port => 25, 
:authentication => :login, 
:user_name => 'johnoggy3010', 
:password => 'secret' 
} 

郵寄/ user_mailer文件:

class UserMailer < ActionMailer::Base 

def mail(user) 
rexipients '[email protected]' 
from '[email protected]' 
subject = "Hi" 
body :user => user 
end 
end 

我的控制器:

UserMailer.deliver_mail(params[:name]) 

和模板user_mailer文件/ welcome_email.html.erb:

<h1>Welcome to example.com,<%= user %> </h1> 

但s omthing是錯誤的,我不知道什麼exacally ...

+1

我當然也不知道。你能發佈你在發送郵件時看到的內容嗎(錯誤消息,格式不正確的電子郵件,其他內容)?順便說一下,「rexipients」不是你拼寫'recipients'的方式...... – PinnyM 2013-04-26 14:19:58

+0

我沒有看到任何錯誤.... – 2013-04-26 14:24:45

+0

那麼,你看到什麼讓你覺得有什麼錯誤? – PinnyM 2013-04-26 14:25:48

回答

1

讓你設置correct.Here是爲使用Gmail SMTP代碼:

config.action_mailer.raise_delivery_errors = true 
    config.action_mailer.default_url_options = { :host => 'your host' } 
    config.action_mailer.delivery_method = :smtp 
    config.action_mailer.smtp_settings = { 
    :address  => 'smtp.gmail.com', 
    :port   => '587', 
    :authentication => :plain, 
    :user_name  => 'your full email addess like [email protected]', 
    :password  => 'your account password', 
    :domain   => 'your domain' 
    } 

在你development.rb寫這下面一行看到如果有任何錯誤發生:

config.action_mailer.raise_delivery_errors = true 

在您的郵件首次嘗試發送這個簡單的電子郵件:

def deliver_oggymail()  
    mail(:to => "[email protected]", :subject => ="hi") 
    end 

在你的控制器裏

UserMailer.deliver_oggymail().deliver 
+0

所有的設置都是正確的。沒有看到顯示和日誌中的一些錯誤。但它仍然不起作用... – 2013-04-26 14:39:59

+1

你看不到任何交貨錯誤?你有沒有收到你的郵件到你的收件箱?你必須說一些關於你的錯誤,除非它不可能解決它。把最後一行加入你的development.rb並重新啓動服務器並嘗試發送並查看你的日誌。 – user2323194 2013-04-26 14:43:36

+0

我重新調整服務器並重試,但仍然沒有看到日誌中的錯誤。並且電子郵件沒有發送... – 2013-04-26 14:52:21