0

localhost からメールを送信できません。これが私のコードです。最初はメーラー UserMailer を生成していました。環境.rb:

config.action_mailer.delivery_method = :smtp

config.action_mailer.smtp_settings = {
 :adress => 'johnoggy3010@gmail.com',
 :port => 25,
 :authentication => :login,
 :user_name => 'johnoggy3010',
 :password => 'secret'
 }

メーラー/user_mailer:

class UserMailer < ActionMailer::Base

def mail(user)
rexipients 'rexipient@gmail.com'
from 'johnoggy3010@gmail.com'
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>

しかし、何かが間違っていて、正確にはわかりません...

4

1 に答える 1

1

make your setting correct.Here is the code for using 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 abc@gmail.com',
  :password       => 'your account password',
  :domain         => 'your domain'
  }

In your development.rb write this following line to see if there is any error happening:

config.action_mailer.raise_delivery_errors = true

In your mailer first try to send this simple email:

  def deliver_oggymail()    
    mail(:to => "rexipient@gmail.com", :subject => ="hi")
  end

In your controller

UserMailer.deliver_oggymail().deliver
于 2013-04-26T14:25:14.123 に答える