Sending emails from different domains

769 Views Asked by At

We are currently running our ruby on rails application with SendGrid for sending emails. We have authenticated two subdomains in our SendGrid account:

  1. test1.mydomain.com
  2. 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?

1

There are 1 best solutions below

0
On

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) as

config.action_mailer.default_options = {from: '[email protected]'}

you can also set it up for each mailer class

class MyAlternativeMailer < ApplicationMailer
  default from: "[email protected]"

  def altmessage
  end
end