# Send email

**URL:** <https://www.ruby-forum.com/t/send-email/148484>\
**Category:** Rails\
**Created:** [September 13, 2008, 11:26am UTC](https://www.ruby-forum.com/t/send-email/148484 "2008-09-13T11:26:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fRAnKEnSTEin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@fRAnKEnSTEin](https://www.ruby-forum.com/u/fRAnKEnSTEin)\
**Post date:** [September 13, 2008, 11:26am UTC](https://www.ruby-forum.com/t/send-email/148484/1 "2008-09-13T11:26:22Z")

</div>

Hi, i am trying to send an email using RoR version 2.1.0 but i get  
some errors. I have this configuration:

1- In config/eviroment.rb, at the very end of my file:

ActionMailer::Base.delivery\_method = :smtp

ActionMailer::Base.smtp\_settings = {  
:address =\> “[smtp.domain.com](http://smtp.domain.com)”,  
:port =\> 25,  
:domain =\> “[domain.com](http://domain.com)”,  
:authentication =\> :login,  
:user\_name =\> “removed\_email\_address@domain.invalid”,  
:password =\> “secret”  
}

ActionMailer::Base.default\_content\_type = “text/html”  
ActionMailer::Base.raise\_delivery\_errors = true

2- app/models/Emailer i have:

class Emailer \< ActionMailer::Base  
def contact\_email(email\_params, sent\_at = Time.now)  
@recipients = “removed\_email\_address@domain.invalid”  
@from = email\_params[:name] + " \<" + email\_params[:address] +  
“\>”  
@subject = email\_params[:subject]  
@sent\_on = sent\_at  
@body[“email\_body”] = email\_params[:body]  
@body[“email\_name”] = email\_params[:name]  
end  
end

3- app/controllers/contact\_controller i have:

class ContactController \< ApplicationController  
def index  
end

def send\_mail  
Emailer::deliver\_contact\_email(params[:email])  
end

end

4- app/views/emailer/contact\_email.rhtml i have:  
Name:

\<%= @email\_name %\>

Message:

\<%= @email\_body %\>

5- in app/view/contact/index.html.erb have:  
\<% form\_tag ‘/contact/send\_mail’ do %\>

| Name: | \<%= text\_field "email", "name", :size =\> 30 %\> |
| Email Address: | \<%= text\_field "email", "address", :size =\> 30 %\> |
| Subject: | \<%= text\_field "email", "subject", :size =\> 30 %\> |
| Body: | \<%= text\_area "email", "body", :rows =\> 8, :cols =\> 30 %\> |

\<%= submit\_tag ‘Send Email’ %\>

\<% end -%\>

5- Errors i got:

Net::SMTPSyntaxError (502 unimplemented (#5.5.1)  
):  
/usr/lib/ruby/1.8/net/smtp.rb:948:in `check_auth_continue' /usr/lib/ruby/1.8/net/smtp.rb:740:in `auth\_login’  
/usr/lib/ruby/1.8/net/smtp.rb:921:in `critical’  
…  
…  
…

I have read a lot in different forums about the same problema but no  
solution found. I also asked to my hosting solution about smtp  
configuration, and they said that i am using the correct information  
about our smtp. So I do not have any idea of what i am doing wrong,  
need help please. Any idea?

Cheers

---

<div class="post-metadata">

**Author:** ![fRAnKEnSTEin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@fRAnKEnSTEin](https://www.ruby-forum.com/u/fRAnKEnSTEin)\
**Post date:** [September 13, 2008, 11:44am UTC](https://www.ruby-forum.com/t/send-email/148484/2 "2008-09-13T11:44:31Z")

</div>

On Sep 13, 10:25 am, fRAnKEnSTEin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> :domain =\> “[domain.com](http://domain.com)”,  
> :authentication =\> :login,  
> :user\_name =\> “removed\_email\_address@domain.invalid”,  
> :password =\> “secret”
> 
> }

Sounds like the mail server doesn’t support the :login authentication  
method (Have you tried the other options ?(:plain, :cram\_md5)).  
Perhaps the server requires no authentication in which case you should  
just remove the :authentication option.

Fred

---

<div class="post-metadata">

**Author:** ![fRAnKEnSTEin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@fRAnKEnSTEin](https://www.ruby-forum.com/u/fRAnKEnSTEin)\
**Post date:** [September 13, 2008, 11:49am UTC](https://www.ruby-forum.com/t/send-email/148484/3 "2008-09-13T11:49:12Z")

</div>

fRAnKEnSTEin wrote:

> :domain =\> “[domain.com](http://domain.com)”,  
> class Emailer \< ActionMailer::Base
> 
> end  
> 5- in app/view/contact/index.html.erb have:  
>   
> \<%= submit\_tag ‘Send Email’ %\>  
> …  
> …  
> …
> 
> I have read a lot in different forums about the same problema but no  
> solution found. I also asked to my hosting solution about smtp  
> configuration, and they said that i am using the correct information  
> about our smtp. So I do not have any idea of what i am doing wrong,  
> need help please. Any idea?
> 
> Cheers

You may try telnet’ing in to port 25 of your smtp server and issuing the  
EHLO (or HELO) command and verify that one of the auth types supported  
is LOGIN.

Are you certain your server requires authentication to send email?

Cheers,  
Darrik

–  
Darrik Mazey  
DMT Programming, LLC.

---

<div class="post-metadata">

**Author:** ![fRAnKEnSTEin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@fRAnKEnSTEin](https://www.ruby-forum.com/u/fRAnKEnSTEin)\
**Post date:** [September 13, 2008, 2:22pm UTC](https://www.ruby-forum.com/t/send-email/148484/4 "2008-09-13T14:22:37Z")

</div>

Hi,

Thank you for your fast response. Ok i fixed the issue. The problema  
was that i was using smtp as a backend in the instruction:

ActionMailer::Base.delivery\_method = :smtp

Our server uses sendmail, i just changed to this:

ActionMailer::Base.delivery\_method = :sendmail

and it works perfectly. :-]

But i got now another little problem(i am a noob in RoR) the app send  
an error like:

ActionView::MissingTemplate (Missing template contact/  
send\_mail.html.erb in view path /home/lumenap/public\_html/contact/app/  
views):  
…  
…  
…

The error is totally correct, because in my app/controllers/  
contact\_controller i have:

class ContactController \< ApplicationController  
def index  
end  
def send\_mail  
Emailer::deliver\_contact\_email(params[:email])  
end  
end

As you see i am not rendering any iew, so if i want to render se same  
page that i am workin with(the index) what i shuold put? I puted an  
render :text =\> “somthing” just for testing but it does not work, gave  
me the same error. How can i render the index page?

Regards,

shirkavand

---

<div class="post-metadata">

**Author:** ![fRAnKEnSTEin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/0ea827/32.png) [@fRAnKEnSTEin](https://www.ruby-forum.com/u/fRAnKEnSTEin)\
**Post date:** [September 13, 2008, 2:53pm UTC](https://www.ruby-forum.com/t/send-email/148484/5 "2008-09-13T14:53:02Z")

</div>

Hi,

Ok i fixed that too. I just add in my controller action an redirection  
to an action, like so:

class ContactController \< ApplicationController  
def index  
end  
def send\_mail  
Emailer::deliver\_contact\_email(params[:email])  
redirect\_to :action =\> ‘index’  
end  
end

That works great, now everything works perfectly :).

Thank you very much for your support. Have a nice day

Shirkavand
