首页 > 解决方案 > 从不同域发送电子邮件

问题描述

我们目前正在使用 SendGrid 运行我们的 ruby​​ on rails 应用程序来发送电子邮件。我们在 SendGrid 帐户中验证了两个子域:

  1. test1.mydomain.com
  2. test2.mydomain.com

目前发送电子邮件的默认域test1.mydomain.com是在 SendGrid 中配置的。

但是我们想从子域发送一些电子邮件,test2.mydomain.com而从test1.mydomain.com. 是否可以从 ruby​​ on rails 应用程序发送来自不同域的电子邮件?

标签: ruby-on-railssendgridsendgrid-rubysendgrid-rails

解决方案


一部分是为两个域设置 MX 和其他基于 DNS 的验证。如果需要,Sendgrid 文档将为您提供帮助:https ://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/

然后,在您的邮件中,您可以设置一个“发件人”地址,该地址将显示为发件人。

如果通常您将其配置一次(在 中config/environment/production.rb)为

config.action_mailer.default_options = {from: 'no-reply@example.com'}

您还可以为每个邮件程序类设置它

class MyAlternativeMailer < ApplicationMailer
  default from: "from@altdomain.example.com"

  def altmessage
  end
end

推荐阅读