Hi,
I've got actionmailer set to raise an error on failure. When a user submits my contact form, and they use a bogus address 's@s.com', then the following error occurs in the production.log:
Net::SMTPFatalError (553 5.1.8 Sender address <s@s.com> domain does not exist)
What I would like to do is catch the error, add the message to the errors for the email address field, and redisplay the form.
I'm sure that ruby/rails can somehow catch the error, probably with some sort of rescue. I couldn't find much in the way of reference to how to use the rescue handling on rails. Are there any docs for this, beyond just the rdoc?
Here is my existing action:
def contact
@contact = Contact.new
if request.post?
@contact.attributes = params[:contact]
if @contact.valid?
email = UserNotifier.create_contact_request(@contact)
UserNotifier.deliver(email)
render(:text => '<p class="fieldWithErrors">Thank you for your
comment or question. Our staff will reply as soon as possible.</p>',
:layout => '/layouts/application.rhtml')
end
else
if logged_in?
@contact.name = current_user.fullname
@contact.telephone = current_user.telephone
@contact.email = current_user.email
end
end
end
Thanks!
Regards, Rich