We are currently running our ruby on rails application with SendGrid for sending emails. We have authenticated two subdomains in our SendGrid account:
- test1.mydomain.com
- test2.mydomain.com
Currently the default domain for sending emails is test1.mydomain.com
which is configured in SendGrid.
But we want to send few emails from the subdomain test2.mydomain.com
and others from test1.mydomain.com
. Is it possible to send emails from different domains from a ruby on rails application?
One part is to set up the MX and other DNS-based verifications for both domains. Sendgrid documentation will help you there if needed: https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/
Then, in your mailer, you can set up a "from" address, which will appear as the sender.
If usually you would configure it once (in
config/environment/production.rb
) asyou can also set it up for each mailer class