fix(leadmail): extract from-display via addrs.first.display_name; log payload from
Previous extract_from used message[:from].display_names.first. That
method exists on Mail::Field but its behavior across Mail gem versions
is inconsistent — it sometimes returns a string, sometimes blank. The
canonical Mail gem API for getting the display name of the first
address in a multi-address field is addrs.first.display_name, which
returns the parsed display name reliably.
Without a working display name extraction, our LeadMail payload only
included {email: ...} without the name, so emails arrived showing only
the bare 'dev@leadmagnet.fi' instead of 'Niklas Pull from Lead Magnet
Dev <dev@leadmagnet.fi>'.
Also include the from payload (email + name) in the success log line so
future from-header issues are immediately visible without needing to
check LeadMail's dashboard.
This commit is contained in:
@@ -15,7 +15,10 @@ class LeadmailDelivery
|
||||
|
||||
response_data = JSON.parse(response.body)
|
||||
message.header['X-LeadMail-Log-ID'] = response_data.dig('data', 'log_id')
|
||||
Rails.logger.info("Email sent via LeadMail: log_id=#{response_data.dig('data', 'log_id')}, to=#{message.to.inspect}")
|
||||
Rails.logger.info(
|
||||
"Email sent via LeadMail: log_id=#{response_data.dig('data', 'log_id')} " \
|
||||
"from=#{payload[:from].inspect} to=#{message.to.inspect}"
|
||||
)
|
||||
response
|
||||
rescue StandardError => e
|
||||
Rails.logger.error("LeadMail delivery failed: #{e.message}\nPayload: #{payload.inspect}")
|
||||
@@ -51,8 +54,9 @@ class LeadmailDelivery
|
||||
end
|
||||
|
||||
def extract_from(message)
|
||||
from_field = message[:from]
|
||||
from_address = message.from&.first
|
||||
from_display = message[:from]&.display_names&.first
|
||||
from_display = from_field&.addrs&.first&.display_name
|
||||
|
||||
{
|
||||
email: from_address,
|
||||
|
||||
Reference in New Issue
Block a user