# Sending email

**URL:** <https://www.ruby-forum.com/t/sending-email/110121>\
**Category:** Rails\
**Created:** [July 23, 2007, 3:17pm UTC](https://www.ruby-forum.com/t/sending-email/110121 "2007-07-23T15:17:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nagesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7ba0ec/32.png) [@nagesh](https://www.ruby-forum.com/u/nagesh)\
**Post date:** [July 23, 2007, 3:17pm UTC](https://www.ruby-forum.com/t/sending-email/110121/1 "2007-07-23T15:17:17Z")

</div>

## i had generated the controller as:

class EmailerController \< ApplicationController  
def sendmail  
email = @params[“email”]  
recipient = email[recipient]  
subject = email[subject]  
message = email[message]  
Emailer.deliver\_contact(recipient, subject, message)  
return if request.xhr?  
render :text =\> ‘Sucessfully sent a mail…’  
end  
def index  
render :file =\> ‘app\views\emailer\index.rhtml’  
end

end

## and model as:

class Emailer \< ActionMailer::Base  
def contact(recipient, subject, message, sent\_at = Time.now)  
@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 = {}  
end

end

## in environment.rb i had given like this:

ActionMailer::Base.delivery\_method =:sendmail  
ActionMailer::Base.server\_settings = {  
:address =\> “localhost”,  
:port =\> 25,  
:domain =\> “[gmail.com](http://gmail.com)”,  
:authentication =\> :login,  
:user\_name =\> “username”,  
:password =\> "password  
}

## and in app\views\emailer\contact.rhtml:

Hi!

You are having one email message from \<%= @email %\> with a tilte

\<%= @title %\>  
and following is the message:  
\<%= @message %\>

Thanks

## and in app\views\emailer\index.rhtml:

# Send Email
\<%= start\_form\_tag :action =\> 'sendmail' %\>

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

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

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

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

but still i cannot able to send the mails… what are the changes  
required please kindly send me code…

---

<div class="post-metadata">

**Author:** ![nagesh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7ba0ec/32.png) [@nagesh](https://www.ruby-forum.com/u/nagesh)\
**Post date:** [July 23, 2007, 7:18pm UTC](https://www.ruby-forum.com/t/sending-email/110121/2 "2007-07-23T19:18:57Z")

</div>

If you like screencasts, there is a really good railscast primer on  
sending email that was posted today.

> **[\#61 Sending Email - RailsCasts](http://railscasts.com/episodes/61-sending-email)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

-STephanie

On Jul 23, 6:17 am, Nagesh S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
