使用 ruby​​ on Rails 通过 gmail 使用 SMTP 通过 sendgrid 发送电子邮件

发布于 2024-11-15 08:33:47 字数 1263 浏览 2 评论 0原文

我正在做一个 ruby​​ on Rails 项目,他们想使用 sendgrid,但他们也喜欢 gmail。使用 gmail,它允许您使用不同的别名从网络浏览器发送电子邮件,但现在还支持通过另一个 smtp 服务器而不是他们自己的服务器发送电子邮件。

我想知道是否可以将一封电子邮件从 RoR 项目发送到 gmail(这样管理层就可以保持其良好的界面和发件箱),但随后它会将其转发到 sendgrid SMTP 服务器。只是为了澄清一下,我知道如何并且目前可以通过 gmail 作为不同的别名发送电子邮件,但这专门是为了在到达 gmail 后将其转发到 sendgrid。

我目前有一个标准设置:

Myapp::Application.configure do
  config.action_mailer.default_url_options = { :host => 'www.mygenericwebsite.com' }  

  config.action_mailer.delivery_method = :smtp 
  config.action_mailer.smtp_settings = {
          :enable_starttls_auto => true, 
          :address => 'smtp.gmail.com',  
          :port => 587,
          :tls => true,
          :authentication => :plain,
          :domain => 'mygenericwebsite.com',
          :user_name => "[email protected]",
          :password => "pA55w0RD"
          }

class UserMailer < ActionMailer::Base
  default :from => "HappyAdmin <[email protected]>"

Im doing a ruby on rails project for work and they would like to use sendgrid, but they also like gmail. With gmail it allows you to send an email from the web browser under a different alias but now also supports sending that through another smtp server instead of their own.

I was wondering if then, it would be possible to send an email from the RoR project through to gmail (so management gets to keep their nice interface and sent box), but then it would forward it through to the sendgrid SMTP servers. Just to clarify I know how to and currently can send an email through gmail as a different alias, but this is specifically to forward it through to sendgrid after it gets to gmail.

I currently have a standard setup of:

Myapp::Application.configure do
  config.action_mailer.default_url_options = { :host => 'www.mygenericwebsite.com' }  

  config.action_mailer.delivery_method = :smtp 
  config.action_mailer.smtp_settings = {
          :enable_starttls_auto => true, 
          :address => 'smtp.gmail.com',  
          :port => 587,
          :tls => true,
          :authentication => :plain,
          :domain => 'mygenericwebsite.com',
          :user_name => "[email protected]",
          :password => "pA55w0RD"
          }

class UserMailer < ActionMailer::Base
  default :from => "HappyAdmin <[email protected]>"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋叶绚丽 2024-11-22 08:33:47

您可以通过 Sendgrid 和密件抄送发送电子邮件中的 Gmail 地址,然后根据发件人地址从应用程序为电子邮件应用标签。不确定您是否可以应用“已发送”标签,但另一个标签可能就可以了。我认为这比每封电子邮件发送两次更简单、更可靠。

You could send via Sendgrid and BCC the Gmail address in your emails, and then apply a label to emails from the app based on the From address. Not sure if you can apply the Sent label, but another label would probably be all right. I think this would be simpler and more robust than sending each email twice.

梦萦几度 2024-11-22 08:33:47

只是想指出,如果您愿意,我们的产品 PostageApp 将允许您通过 Google SMTP 发送。您所要做的就是将 SMTP 详细信息添加到您的项目中,然后就可以开始了。

我刚刚检查了与 Postage 连接的个人项目,所有发出的电子邮件都出现在“已发送邮件”文件夹中。

如果这就是您正在寻找的内容,或者您​​有任何其他问题,请告诉我!

Just wanted to point out that our product, PostageApp, will allow you to send via the Google SMTP if you are so inclined. All you have to do is add the SMTP details to your project and you're good to go.

I just checked with the personal project I have hooked up with Postage and all the emails sent out appear in the Sent Mail folder.

Let me know if that's what you're looking for, or if you have any other questions!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文