Forum: Ruby on Rails scheduling mails in 2.3.8

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
0ffb9af59e0cd9ab45b5afa0bed7eeb7?d=identicon&s=25 honey j. (honeyruby)
on 2012-07-20 13:23
(Received via mailing list)
Hi all,

      How can i send mails in rails 2.3.8 and schedule them when i need
i've tried with whenever gem but it did not work properly . can any one
help me out .

thanks in advance
terasawan (Guest)
on 2012-07-23 10:42
(Received via mailing list)

I think you should use cron and `script/runner'.

2012/7/20 honey ruby <>:
Ba70810a4ad80a1991e7fdeab9b35b25?d=identicon&s=25 praneeth t. (praneeththota)
on 2012-07-23 13:38
(Received via mailing list)
write the following code in development.rb

config.action_mailer.raise_delivery_errors = false

config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:tls => true,
:enable_starttls_auto => true,
:address => '',
:port => 587,
:authentication => :plain,
:user_name => '',
:password => 'password'

in emailer model write the following code:

class Emailer < ActionMailer::Base

def contact(recipient, subject, message, sent_at =, files=[])
      @subject = subject
      @recipients = recipient
      @from = ''
      @sent_on = sent_at
  @body["title"] = 'This is title'
    @body["email"] = ''
     @body["message"] = message
      @headers = {}

  files.each do |file|
    attachment "application/octet-stream" do |a|
      a.body =
      a.filename = file.original_filename
    end unless file.blank?


create one view and follow the code:

<h1>Send Email</h1>
<% form_for(:emailer, @emailer, :url=>{:action=>'sendmail'},
:html=>{:multipart=>true}) do |f| %>
<%= f.error_messages %>

<p><label for="email_subject">Subject</label>:
<%= text_field 'email', 'subject' %></p>
<p><label for="email_recipient">Recipient</label>:
<%= text_field 'email', 'recipient' %></p>
<p><label for="email_message">Message</label><br/>
<%= text_area 'email', 'message' %></p>
<p><label for="file_upload">Upload</label><br/>
<%= file_field 'email', 'file' %></p>
<%= submit_tag "Send" %>
<% end %>

write the code in the controller:

class EmailerController < ApplicationController
   def index

   def sendmail

@uploaded_files = []
email = params["email"]
 puts email["file"]
@uploaded_files << email["file"]
  recipient = email["recipient"]
  subject = email["subject"]
  message = email["message"]
      Emailer.deliver_contact(recipient, subject, message,
      return if request.xhr?
  @email = recipient
  @subject = subject
  @message = message
       render :file => 'app\views\emailer\contact.rhtml'

This topic is locked and can not be replied to.