Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amazon SES raise SMTP Error Net::SMTPFatalError (554 Transaction failed: Empty address) #125

Open
ippachi opened this issue Dec 21, 2021 · 3 comments
Assignees
Labels

Comments

@ippachi
Copy link

ippachi commented Dec 21, 2021

When using hanami/mailer with Amazon SES, this raises Net::SMTPFatalError (554 Transaction failed: Empty address) because of the empty Return-Path header.

Hanami::Mailer.new seems to set nil to Return-Path and send an email with empty Return-Path finally.
I think Hanami::Mailer shouldn't send Return-Path if that is nil.

I don't know that point out is correct because I'm not familiar with mail protocol.
What do you think about that?

@jodosha jodosha self-assigned this Dec 21, 2021
@jodosha jodosha added the bug label Dec 21, 2021
@jodosha
Copy link
Member

jodosha commented Dec 21, 2021

@ippachi Do you have an example of the failing Mailer? I can't reproduce the problem with unit tests.

@ippachi
Copy link
Author

ippachi commented Dec 21, 2021

require 'hanami/mailer'

Hanami::Mailer.configure do
  delivery_method :smtp,
    address:              "email-smtp.ap-northeast-1.amazonaws.com",
    port:                 587,
    user_name:            ENV['AWS_SES_USERNAME'],
    password:             ENV['AWS_SES_PASSWORD'],
    authentication:       "plain",
    enable_starttls_auto: true
end.load!

class WelcomeMailer
  include Hanami::Mailer

  from 'from@example.com'
  to 'to@example.com'
  template 'test'

  subject 'Welcome'

  def self.templates(*); end
end

WelcomeMailer.deliver

This code raises 554 Transaction failed: Empty address (Net::SMTPFatalError).
But I have been able to confirm in Aws SES only. I don't know that problem has occurred on other mail servers.

@ippachi
Copy link
Author

ippachi commented Dec 21, 2021

module Hanami
  module Mailer
    def build
      Mail.new.tap do |m|
        # m.return_path = __dsl(:return_path)
        m.from     = __dsl(:from)
        m.to       = __dsl(:to)
        m.cc       = __dsl(:cc)
        m.bcc      = __dsl(:bcc)
        m.reply_to = __dsl(:reply_to)
        m.subject  = __dsl(:subject)

        m.charset   = charset
        m.html_part = __part(:html)
        m.text_part = __part(:txt)

        m.delivery_method(*Hanami::Mailer.configuration.delivery_method)
      end
    end
  end
end

This is my hotfix code. This hotfix works well. (I don't need to specify return-path)
My idea is that checking is return-path nil before assigned m.return_path like below code.

def build
      Mail.new.tap do |m|
        unless __dsl(:return_path).nil?
          m.return_path = __dsl(:return_path)
        end
        m.from     = __dsl(:from)
        m.to       = __dsl(:to)
        m.cc       = __dsl(:cc)
        m.bcc      = __dsl(:bcc)
        m.reply_to = __dsl(:reply_to)
        m.subject  = __dsl(:subject)

        m.charset   = charset
        m.html_part = __part(:html)
        m.text_part = __part(:txt)

        m.delivery_method(*Hanami::Mailer.configuration.delivery_method)
      end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants