Email section

Sir , I want to implement email section in ma web application..
so i found the method 'server_setting' for it...
Following is the method:

config.action_mailer.server_settings = {
  :address => "smtp.gmail.com" ,
  :port => 25,
  :domain => "gmail.com" ,
  :authentication => :login,
  :user_name => "manish" ,
  :password => "belsare"
}

sir but wen i restart my web server following errors are generated:

[root@localhost ksmm]# script/server
=> Booting WEBrick
=> Rails 2.3.4 application starting on http://0.0.0.0:3000
/usr/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/rails/gem_dependency.rb:119:Warning:
Gem::Dependency#version_requirements is deprecated and will be removed
on or after August 2010. Use #requirement
/usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:402:in
`method_missing': undefined method `server_settings=' for
ActionMailer::Base:Class (NoMethodError)
  from /usr/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:602:in
`send'
  from /usr/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:602:in
`initialize_framework_settings'
  from /usr/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:601:in
`each'
  from /usr/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:601:in
`initialize_framework_settings'
  from /usr/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:598:in
`each'
  from /usr/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:598:in
`initialize_framework_settings'
  from /usr/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:155:in
`process'
  from /usr/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/initializer.rb:113:in
`send'
   ... 7 levels...
  from /usr/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/commands/server.rb:84
  from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
  from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
  from script/server:3

what shud i do 2 avoid this problem..
Is it because of the version of rails?

Hi,

It was probably for old action mailer. You should use
config.action_mailer.smtp_settings

Sir for the following suggestion it works well..

config.action_mailer.smtp_settings

But wen i further implement it..
It givs the following error:

getaddrinfo: Temporary failure in name resolution

Application Trace:

/usr/lib/ruby/1.8/net/protocol.rb:206:in `initialize'
/usr/lib/ruby/1.8/net/protocol.rb:206:in `new'
/usr/lib/ruby/1.8/net/protocol.rb:206:in `old_open'
/usr/lib/ruby/1.8/timeout.rb:62:in `timeout'
/usr/lib/ruby/1.8/timeout.rb:93:in `timeout'
/usr/lib/ruby/1.8/net/protocol.rb:206:in `old_open'
/usr/lib/ruby/1.8/net/smtp.rb:392:in `do_start'
/usr/lib/ruby/1.8/net/smtp.rb:377:in `start'
/usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:684:in
`perform_delivery_smtp'
/usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:525:in
`__send__'
/usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:525:in
`deliver!'
/usr/lib/ruby/gems/1.8/gems/actionmailer-2.3.4/lib/action_mailer/base.rb:397:in
`method_missing'
/root/ksmm/app/controllers/email_controller.rb:12:in `remind'

SIr following errors were generated.Can u please help meh regarding
diz..
Thanks in Advance!

def remind
  @title = "Mail me my login information"
  if param_posted?(:user)
      email = params[:user][:email]
       user = User.find_by_email(email)
       if user
        UserMailer.deliver_reminder(user)
          flash[:notice] = "Login information was sent."
          redirect_to :action => "index", :controller => "site"
         else
         flash[:notice] = "There is no user with that email address."
       end
    end
  end

Sir this is the code that we implemented in email_controller for :action
=> "remind"

Do i need to make any corrections in diz code?

Manish,

/root/ksmm/app/controllers/email_controller.rb:12:in `remind'

It says there is an error on line 12. I'm guessing this is the line

      UserMailer.deliver_reminder(user)

You might want to paste the code for that method too.

Punit

class EmailController < ApplicationController

include ProfileHelper
before_filter :protect, :only => [ "correspond" ]

  def remind
  @title = "Mail me my login information"
  if param_posted?(:user)
      email = params[:user][:email]
       user = User.find_by_email(email)
       if user
        UserMailer.deliver_reminder(user)
          flash[:notice] = "Login information was sent."
          redirect_to :action => "index", :controller => "site"
         else
         flash[:notice] = "There is no user with that email address."
       end
    end
  end

def email_sent

    MyMailer::deliver_mail("recipient.address@example.com")

  end

  def correspond
    user = User.find(session[:user_id])

    id=session[:user_id]
     Personal.find_each do |@per|
        if(@per.user_id == id) # id is user id
          @per_id = "#{@per.id}" #que_id is question_id
          break
        end
     end
     idd=@per_id
     #flash[:notice] = idd
     iddd=idd.to_i

    recipient = User.find_by_user_name(params[:id])

    @title = "Email: #{@per.first_name} #{@per.last_name}
(#{user.user_name}) :: Recipient: #{recipient.user_name}"
    if param_posted?(:message)
      @message = Message.new(params[:message])
      if @message.valid?
        UserMailer.deliver_message(
          :user => user,
          :recipient => recipient,
          :message => @message,
          :user_url => profile_for(user),
          :reply_url => url_for(:action => "correspond",
                                :id => user.user_name)
        )
        flash[:notice] = "Email sent."
        redirect_to profile_for(recipient)
      end
    end
  end

end

ya diz is the code for email_controller....
Can u please tell me what is the problem that the email is not being
sent?

class UserMailer < ActionMailer::Base
def reminder(user)
   @subject = 'Your login information at KnowledgeEngine.com'
   @body = {}
   #Give body access to the user information.
   @body["user"] = user
   @recipients = user.email
   @from = 'KnowldegeEngine <do-not-reply@knowledgeengine.com>'
end

def message(mail)
  subject mail[:message].subject
  from 'KnowledgeEngine <do-not-reply@knowledgeengine.com>'
  recipients mail[:recipient].email
  body mail
end

end

diz is the code for UserMailer..