# Scheduling mails in 2.3.8

**URL:** <https://www.ruby-forum.com/t/scheduling-mails-in-2-3-8/221586>\
**Category:** Rails\
**Created:** [July 20, 2012, 1:23pm UTC](https://www.ruby-forum.com/t/scheduling-mails-in-2-3-8/221586 "2012-07-20T13:23:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [July 20, 2012, 1:23pm UTC](https://www.ruby-forum.com/t/scheduling-mails-in-2-3-8/221586/1 "2012-07-20T13:23:34Z")

</div>

Hi all,

```
  How can i send mails in rails 2.3.8 and schedule them when i need 

```

it.  
i’ve tried with whenever gem but it did not work properly . can any one  
help me out .

thanks in advance

---

<div class="post-metadata">

**Author:** ![honeyruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/278dde/32.png) [@honeyruby](https://www.ruby-forum.com/u/honeyruby)\
**Post date:** [July 23, 2012, 10:42am UTC](https://www.ruby-forum.com/t/scheduling-mails-in-2-3-8/221586/2 "2012-07-23T10:42:21Z")

</div>

Hi.

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

2012/7/20 honey ruby [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![honeyruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/278dde/32.png) [@honeyruby](https://www.ruby-forum.com/u/honeyruby)\
**Post date:** [July 23, 2012, 1:38pm UTC](https://www.ruby-forum.com/t/scheduling-mails-in-2-3-8/221586/3 "2012-07-23T13:38:17Z")

</div>

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 =\> ‘[smtp.gmail.com](http://smtp.gmail.com)’,  
:port =\> 587,  
:authentication =\> :plain,  
:user\_name =\> ‘removed\_email\_address@domain.invalid’,  
:password =\> ‘password’  
}

in emailer model write the following code:

class Emailer \< ActionMailer::Base

def contact(recipient, subject, message, sent\_at = Time.now, files=[])  
@subject = subject  
@recipients = recipient  
@from = ‘removed\_email\_address@domain.invalid’  
@sent\_on = sent\_at  
@body[“title”] = ‘This is title’  
@body[“email”] = ‘removed\_email\_address@domain.invalid’  
@body[“message”] = message  
@headers = {}

files.each do |file|  
attachment “application/octet-stream” do |a|  
a.body = file.read  
a.filename = file.original\_filename  
end unless file.blank?  
end

end  
end

create one view and follow the code:

# Send Email
\<% form\_for(:emailer, @emailer, :url=\>{:action=\>'sendmail'}, :html=\>{:multipart=\>true}) do |f| %\> \<%= f.error\_messages %\>

Subject: \<%= text\_field 'email', 'subject' %\>

Recipient: \<%= text\_field 'email', 'recipient' %\>

Message  
\<%= text\_area 'email', 'message' %\>

Upload  
\<%= file\_field 'email', 'file' %\>

\<%= submit\_tag "Send" %\> \<% end %\>

write the code in the controller:

class EmailerController \< ApplicationController  
def index

end  
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,  
@uploaded\_files)  
return if request.xhr?  
@email = recipient  
@subject = subject  
@message = message  
render :file =\> ‘app\views\emailer\contact.rhtml’  
end

end
