title: Rails + SendGrid Unauthenticated senders not allowed
body: <p>I'm currently working on sending emails via sendgrid and currently sending emails to new users is working.  ...But strangely, very similar emailing options aren't working - the full email including the recipient is displayed in the log but is never received.</p>
  
  <p>Here's what I have:</p>
  
  <p>In a mail.rb file in initializers:</p>
  
  <pre><code>ActionMailer::Base.smtp_settings = {
    :address        =&gt; 'smtp.sendgrid.net',
    :port           =&gt; '587',
    :authentication =&gt; :plain,
    :user_name      =&gt; configatron.sendgrid.username,
    :password       =&gt; configatron.sendgrid.password,
    :domain         =&gt; 'heroku.com'
  }
  
  ActionMailer::Base.delivery_method = :smtp
  </code></pre>
  
  <p>with the username and password being defined elsewhere - they are confirmed to have their correct values</p>
  
  <p>When a new user registers, I call my UserMailer class and do the following:</p>
  
  <pre><code>def welcome_email(user)
      @email = user.email
      @name = user.full_name
  
      mail(to: @email, subject: "Welcome!")
  end
  </code></pre>
  
  <p>And the worker calls it by simply doing the following:</p>
  
  <pre><code>UserMailer.welcome_email(user).deliver
  </code></pre>
  
  <p>This much works; I receive the email and that's that.</p>
  
  <p>But when I try to send an email from a different method, magically things break down.</p>
  
  <p>In the SAME UserMailer class:</p>
  
  <pre><code>def request(org, recipient, item)
    @org = org
    @recipient = recipient
    @item = item
  
    mail(to: @org.email, subject: "A new request has been posted!")
  end
  </code></pre>
  
  <p>Using the SAME function (although this time outside of a worker so I can debug easily):</p>
  
  <pre><code>UserMailer.request(org, recipient, item).deliver
  </code></pre>
  
  <p>The email appears in the terminal perfectly:</p>
  
  <pre><code>Sent mail to mypersonalemail@test.com (4717ms)
  Date: Mon, 31 Dec 2012 01:03:35 -0800
  From: mysendingemail@test.com
  To: mypersonalemail@test.com
  Message-ID: &lt;[longhexstring]@localhost.localdomain.mail&gt;
  Subject: A new request has been posted!
  Mime-Version: 1.0
  Content-Type: multipart/alternative;
  boundary="--==_mimepart_50e154e769903_3c41bba7ec576d5";
  charset=UTF-8
  Content-Transfer-Encoding: 7bit
  
  
  
  ----==_mimepart_50e154e769903_3c41bba7ec576d5
  Date: Mon, 31 Dec 2012 01:03:35 -0800
  Mime-Version: 1.0
  Content-Type: text/plain;
  charset=UTF-8
  Content-Transfer-Encoding: 7bit
  Content-ID: &lt;[longhex]@localhost.localdomain.mail&gt;
  
  Hello world!
  
  ----==_mimepart_50e154e769903_3c41bba7ec576d5
  Date: Mon, 31 Dec 2012 01:03:35 -0800
  Mime-Version: 1.0
  Content-Type: text/html;
  charset=UTF-8
  Content-Transfer-Encoding: 7bit
  Content-ID: &lt;[longhex]@localhost.localdomain.
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /&gt;
  &lt;/head&gt;
    &lt;body&gt;
      &lt;p&gt;
  Hello world!
      &lt;/p&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>But, I check my inbox on my personal email, the junk, the trash, and received nothing.  Even sendgrid has no logs of me ever requesting to send request emails!  But the welcome emails are working perfectly fine, and even are logged through sendgrid.  I don't see what could cause one group of emails to send but not another and this is really baffling.  No obvious errors in syntax jump out at me, and the values I use are of the correct datatype and not nil.</p>
  
  <p>Any help with this strange issue would be extremely appreciated.</p>