Send email

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”,
:port => 25,
:domain => “domain.com”,
:authentication => :login,
:user_name => “[email protected]”,
: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 = “[email protected]
@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

On Sep 13, 10:25 am, fRAnKEnSTEin [email protected] wrote:

:domain => “domain.com”,
:authentication => :login,
:user_name => “[email protected]”,
: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

fRAnKEnSTEin wrote:

:domain => “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.

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

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