简体   繁体   English

我可以使用相同的ActionMailer从不同的地址发送电子邮件吗?

[英]Can I send email from different addresses using same ActionMailer

I'm using ActionMailer for my Rails 2.3.9 application. 我正在使用ActionMailer来实现我的Rails 2.3.9应用程序。

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

with SMTP configuration 使用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. 但是,当发送电子邮件时,发件人电子邮件显示为user@mydomain.com而不是invite@mydomain.com。

Can I have different SMTP configuration for different email addresses? 我可以为不同的电子邮件地址配置不同的SMTP吗? or Is there a way to set the sender email address from ActionMailer config? 或者有没有办法从ActionMailer配置中设置发件人电子邮件地址?

This is a Gmail SMTP limitation. 这是Gmail SMTP限制。 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设置,并会忽略你from地址。

A possible workaround might be to change the smtp settings dynamically when you need to send as someone else. 可能的解决方法可能是在您需要以其他人身份发送时动态更改smtp设置。

Edit: 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. 修改:您可以进入自己的Gmail帐户的设置,并使用“添加您拥有的其他电子邮件地址”选项,以允许您的帐户通过这些电子邮件地址发送。 I haven't tested it, but it might work. 我没有测试它,但它可能会工作。 (See http://www.mobileread.com/forums/showpost.php?p=21093&postcount=1 ). (参见http://www.mobileread.com/forums/showpost.php?p=21093&postcount=1 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM