ArgumentError: An SMTP To address is required to send a message. Set the message smtp_envelope_to, to , cc, or bcc address

27,113

Solution 1

The error message is not about the SMTP envelope, but about the sender:

An SMTP To address is required to send a message

the rest is just a generic message. Something in your [email protected] is not working. Do you use a real, working address? If not, try with one.

Solution 2

If you use sidekiq+actionmailer. Be careful, while sending email using hash. I was doing something like this MyWorker.perform_async("var1", {email: '[email protected]', var2: 'test1234'})

I banged my head for couple of hours, why it is throwing the above error. Because in the perform_menthod hash[:email] is nil. You need to use hash["email"] to receive the email. I do not know, the reason. But it helped me to get rid of this error.

Solution 3

Is :to => '[email protected]' how it is in your failing environment? If it's not a hardcoded email address, do make sure that a variable containing the to-address is not blank.

You don't have to set Mail::Message#smtp_envelope_to explicitly. It can guess it from its recipients, ie. Mail::Message#destinations (to + cc + bcc), but it doesn't seem to have any.

Share:
27,113

Related videos on Youtube

bulleric
Author by

bulleric

I am a open source administrator and os system developer

Updated on December 22, 2020

Comments

  • bulleric
    bulleric over 3 years

    I got an rails 4 application with following mailer configuration:

    config.action_mailer.delivery_method = :smtp
      config.action_mailer.default_url_options = { host: 'myhost.com' }
      config.action_mailer.perform_deliveries = true
    
      config.action_mailer.smtp_settings = {
        :enable_starttls_auto => true,
        :address            => 'smtp.myhost.com',
        :port               => 587,
        :domain             => 'myhost.com',
        :authentication     => :login,
        :enable_starttls_auto => false,
        :tls                  => false,
        :openssl_verify_mode  => 'none',
        :ssl => false,
        :user_name          => "myusername",
        :password           => "mypassword"
      }
    

    Every time i try to send an mail with an testing mailer setup:

    class TestMailer < ActionMailer::Base
    
      default :from => "[email protected]"
    
      def welcome_email
        mail(:to => "[email protected]", :subject => "Test mail", :body => "Test mail body")
      end
    end
    
    TestMailer.welcome_email.deliver
    

    I got this exception:

    ArgumentError: An SMTP To address is required to send a message. Set the message smtp_envelope_to, to , cc, or bcc address.

    Is it possible that i forget something to set.? And i can't find an configuration option for "smtp_envelope_to"

  • bulleric
    bulleric over 10 years
    Thx my failure was an overriding of an smtp address wich set it to nil Oo
  • Jan Strnádek
    Jan Strnádek about 8 years
    Maybe sorry for offtopic, but the reason why you have to use hash['email'] is thanks to serialization process into redis. Sidekiq creates JSON document, it automatically converts all keys to strings.
  • skplunkerin
    skplunkerin about 7 years
    Simple suggestion and exactly what fixed my problem. My APP_CONFIG value passed in my SMTP default from: was returning nil.