Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: uninitialized constant Smtpapi

I am tyring to push my code to Heroku and the build is failing with

 NameError: uninitialized constant Smtpapi
    /tmp/build_0ce2a697c4ef6c16626b01b82d9463f3/app/helpers/my_mailer_header.rb:1:in `<top (required)>'
    /tmp/build_0ce2a697c4ef6c16626b01b82d9463f3/lib/api_v1/users.rb:3:in `<top (required)>'
    /tmp/build_0ce2a697c4ef6c16626b01b82d9463f3/lib/api_v1/mymedical.rb:3:in `<class:Mymedical>'
    /tmp/build_0ce2a697c4ef6c16626b01b82d9463f3/lib/api_v1/mymedical.rb:1:in `<top (required)>'
    /tmp/build_0ce2a697c4ef6c16626b01b82d9463f3/config/routes.rb:1:in `<top (required)>'
    /tmp/build_0ce2a697c4ef6c16626b01b82d9463f3/vendor/bundle/ruby/2.4.0/gems/railties-4.2.11/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'

I update my Gemfile from Ruby 2.3 to 2.4 and now I am getting this error? Cannot find a solution.

This seems to be the code that is causing the issue.

class MyMailerHeader < Smtpapi::Header

Does Smtpapi not exist in Ruby 2.4.2?

The Smtpapi is part of Send-Grid gem and some other gem.

    sendgrid-ruby (1.1.6)
      faraday (~> 0.9)
      mimemagic
      smtpapi (~> 0.1)
    smtpapi (0.1.0)
like image 978
jdog Avatar asked Dec 02 '25 14:12

jdog


1 Answers

sendgrid-ruby depends on smtpapi only in version 1.x, later versions including current 5.3.0 do not.

Since this error came along with ruby update - it may be due to gems update. This should have been prevented by Gemfile.lock, but if Gemfile contains any mentions of windows (mswin, mingw etc.) Heroku will ignore it.

The gem itself has not been updated for 4 years now, because sendgrid rewrote sendgrid-ruby. Best option is to follow them and update your code too. But for app to run before you do that - you can explicitly lock version of sendgrid-ruby: gem 'sendgrid-ruby', '~>1.1.6'

like image 72
Vasfed Avatar answered Dec 05 '25 05:12

Vasfed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!