Skip to content

Undefined Method smtpapi for an instance of Mail::Message #11

@stephen-found

Description

@stephen-found

System Information

  • Ruby 3.3.5
  • Rails 7.1.5.1
  • Mac OS 15.5 (24F74)

Steps to Reproduce

  • rails new mailer-test
  • add gem to Gemfile gem "mail-x_smtpapi-ksr" and bundle install
  • add random mailer under mailers
class RandomMailer < ApplicationMailer
  default from: 'notifications@example.com'
  
  def welcome_email(recipient)
    @recipient = recipient
    @url = 'http://example.com/login'
    
    # Set the SMTP API category to 'test'
    mail.smtpapi.category = 'test'
    
    mail(
      to: recipient,
      subject: 'Welcome to Our Application!'
    )
  end
end
  • start rails console
mail = RandomMailer.welcome_email('test@example.com')
puts mail.to_s

app/mailers/random_mailer.rb:9:in welcome_email': undefined method smtpapi' for an instance of Mail::Message (NoMethodError)

This was experienced in a production app:

NoMethodError: undefined method `smtpapi' for an instance of Mail::Message
from /bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/message.rb:1389:in `method_missing'

before testing on the new rails app. any info is greatly appreciated

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions