Amazon SES raise SMTP Error `Net::SMTPFatalError (554 Transaction failed: Empty address)`
ippachi opened this issue · comments
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?
@ippachi Do you have an example of the failing Mailer? I can't reproduce the problem with unit tests.
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.
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