Note that there are some explanatory texts on larger screens.

plurals
  1. POActionMailer working fine in terminal, not sending to gmail
    primarykey
    data
    text
    <p>I'm just about in the finishing stages of my website, however I am having trouble with the ActionMailer. It prints out the message just fine, I'm just eager to know how to wire it so it can send to gmail account. I'm primary confused how to route it and configure it properly. I have a contact page that has a model that takes parameters like the recipient, subject, message and the time it was sent: <strong>Mailer model:</strong> <em>Note all this code is on a local machine</em></p> <pre><code>class UserEmail &lt; ActionMailer::Base default from: 'XXX@gmail.com' def contact(sender, subject, message, sent_at = Time.now) @sender = sender @message = message @sent_at = sent_at.strftime("%B %e, %Y at %H:%M") mail(:subject =&gt; subject) end end </code></pre> <p>Here's the <strong>about</strong> controller which the <strong>contact</strong> methods lie in: </p> <pre><code>class AboutController &lt; ApplicationController # ...\controllers\home_controller.rb #---------------------------------------------------- # show contact form def contact @title = "Contact" @sender = '' @subject = '' @message = '' end def sendmail @sender = params[:sender] @subject = params[:subject] @message = params[:message] if validate(@sender, @subject, @message) UserEmail.contact(@sender, @subject, @message).deliver flash[:success] = "Your message sent sucessfully!" redirect_to about_index_path else flash.now[:error] = "Your message did not send" redirect_to about_index_path end end private def validate(sender, subject, message) @email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i if sender.blank? || subject.blank? || message.blank? @error = "Message not sent: Required information not filled" return false elsif subject.length &gt;= 50 @error = "Message not sent: Subject must be smaller than 50 characters" return false elsif sender[@email_regex].nil? @error = "Message not sent: Email not valid" return false else return true end end end </code></pre> <p>Now this is where I am <strong><em>lost</em></strong>. Here's what my route like to the mailer. Is this routed appropriately?: </p> <pre><code> match '/contact_email', :to =&gt; 'about#sendmail' </code></pre> <p>When I configure the mailer, does the code rest in the application.rb or the development.rb? Here's what I have in my <strong>application.rb</strong>:</p> <pre><code>config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address =&gt; "smtp.gmail.com", :port =&gt; 587, :user_name =&gt; 'XXX@gmail.com', :password =&gt; 'XXX', :authentication =&gt; 'plain', :enable_starttls_auto =&gt; true, } </code></pre> <p>Thanks in advance! </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload