2013-04-26 118 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