我可以使用同一ActionMailer从不同的地址发送电子邮件吗? [英] Can I send email from different addresses using same ActionMailer

查看:108
本文介绍了我可以使用同一ActionMailer从不同的地址发送电子邮件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Rails 2.3.9应用程序中使用ActionMailer。

I'm using ActionMailer for my Rails 2.3.9 application.

当我使用以下方式发送电子邮件时:

When I send an email using:

  deliver_user_invite

config:

  def user_invite(subject, content)
    subject subject
    from "User Invite <invite@mydomain.com>"
    recipients "invites@mydomain.com"
    sent_on Time.now
    content_type "text/html"
    body :content => content
  end

具有SMTP配置

  config.action_mailer.smtp_settings = {
      :enable_starttls_auto => true,
      :address        => 'smtp.gmail.com',
      :port           => 587,
      :domain         => 'mydomain.com',
      :authentication => :plain,
      :user_name      => 'user@mydomain.com',
      :password       => 'password'    
  }

但是,发送电子邮件时,发件人电子邮件将显示为用户

However when the email is sent, the sender email shows as user@mydomain.com instead of invite@mydomain.com.

我可以为不同的电子邮件地址使用不同的SMTP配置吗?或是否可以通过ActionMailer配置来设置发件人电子邮件地址?

Can I have different SMTP configuration for different email addresses? or Is there a way to set the sender email address from ActionMailer config?

推荐答案

这是Gmail SMTP的限制。它将始终使电子邮件的发件人成为您用于smtp设置的用户名/登录名,并且将忽略您的来自地址。

This is a Gmail SMTP limitation. It will always make the sender of the e-mail be the username/login you use for your smtp settings, and will ignore your from address.

一种可能的解决方法可能是当您需要以其他人的身份发送时动态更改smtp设置。

A possible workaround might be to change the smtp settings dynamically when you need to send as someone else.

编辑:您也许可以进入自己的Gmail帐户的设置,并使用添加您拥有的另一个电子邮件地址选项,以允许您的帐户通过这些电子邮件地址进行发送。我还没有测试过,但是可能可以。 (请参见 http://www.mobileread.com/forums/showpost .php?p = 21093& postcount = 1 )。

You might be able to go into the settings for your own Gmail account and use the "Add another email address you own" option to allow your account to send through those e-mail addresses. I haven't tested it, but it might work. (See http://www.mobileread.com/forums/showpost.php?p=21093&postcount=1).

这篇关于我可以使用同一ActionMailer从不同的地址发送电子邮件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆