ramesh
ramesh

Reputation: 4082

Send mails using ruby on rails

In one of my rails application I have to send a email. I just configured my app like follows.

I am using Rails v2.0.

environment.rb:

RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION

# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')

Rails::Initializer.run do |config|
  config.action_controller.session = {
    :session_key => '_mailtest_session',
    :secret      => 'key_here'
  }
   ActionMailer::Base.delivery_method = :smtp
   ActionMailer::Base.smtp_settings = {
    :address => "smtp.gmail.com",
    :port => 25,
    :domain => "gmail.com",
    :authentication => :login,
    :user_name => "mailid@mailid.com",
    :password => "password"
  }

  ActionMailer::Base.default_content_type = "text/html"
end

models/notifier.rb:

class Notifier < ActionMailer::Base

     def contact(recipient, subject, message, sent_at = Time.now)
      @subject = subject
      @recipients = recipient
      @from = 'from@mail.com'
      @sent_on = sent_at
      @body["title"] = 'Signup Info'
      @body["email"] = 'mail@mail.com'
      @body["message"] = message
      @headers = {}
      return true
   end
end

controller/administrator

class AdministratorController < ApplicationController
  def index
    recipient = "tomailid@mail.com"
    subject = "Subject"
    message = "message"
    Notifier.deliver_contact(recipient, subject, message)
  end
end

When I tried to call index method I m getting this error:

Couldn't find template file for notifier/contact in ["D:/Rails/rails_apps/mailtest/app/views"]

Please help ...

Upvotes: 0

Views: 445

Answers (1)

rkb
rkb

Reputation: 3542

Create a directory named notifier under app/views, and place contact.html.erb there. One of Rails' conventions is that it expects the view directory to be named after the mailer/controller class.

Upvotes: 1

Related Questions