3
votes

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 <[email protected]>"
    recipients "[email protected]"
    sent_on Time.now
    content_type "text/html"
    body :content => content
  end

with SMTP configuration

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

However when the email is sent, the sender email shows as [email protected] instead of [email protected].

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

1
Unrelated to your question, but Rails 2.3.11 is out with lots of security fixes so you should update when you can.Andrew Marshall

1 Answers

6
votes

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.

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

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. I haven't tested it, but it might work. (See http://www.mobileread.com/forums/showpost.php?p=21093&postcount=1).