Custom sender address not working with Gmail SMTP in Rails application

I have a Rails 2.1 application configured to send emails through Gmail’s SMTP server. The problem is that regardless of what sender address I specify in my ActionMailer class, all outgoing emails appear to come from my Gmail account address instead of the custom address I want to use.

I’m wondering if this is some kind of security feature that Gmail has implemented to prevent spam and abuse of their SMTP service?

I have tested both approaches in my ActionMailer:

@sender = [email protected]
from '[email protected]'

Both methods produce the same result - the email shows my Gmail address as the sender rather than the custom domain address I specified. Has anyone encountered this issue before and found a solution?

for sure, security’s a big deal. you can add aliases in gmail settings, but if u need more control over sender addresses, using smtp services like sendgrid or mailgun is the way to go.

Yes, what you’re experiencing is indeed Gmail’s anti-spoofing measures at play. I encountered a similar issue when updating an older Rails app for sending customer notifications. While you can set up aliases in Gmail, if you control the domain, consider configuring SPF and DKIM records to authorize Gmail’s servers to send emails on your behalf. Don’t forget that you will still need to verify the email address through Gmail. Personally, I recommend switching to a service like Postmark or AWS SES. They provide a cleaner approach to managing sender addresses without the cumbersome verification steps, which is especially valuable for production applications where maintaining brand integrity is crucial.

Gmail overrides any sender address you set in Rails due to security measures against spoofing. I faced this issue while building a client portal last year. To resolve it, navigate to your Gmail settings, and look for the ‘Send mail as’ option to add your [email protected] address. Gmail will send a verification email to that address, which you need to confirm. After verification, Rails can send emails with your custom sender address via Gmail’s SMTP. Just ensure you have access to the domain to receive the verification email.