Message status not showing sent IP when sending using API (but does when sending using SMTP)
Describe the bug
On the documentation page for webhooks, it shows an example in the message details for sent messages to show the mx server it was sent to, the IP, and the IP it was sent from. Documentation example: "details":"Message sent by SMTP to aspmx.l.google.com (2a00:1450:400c:c0b::1b) (from 2a00:67a0:a:15::2)", link-to-webhook-documentation
When testing this out though (when sending with API) , it only partially works "details": "Message for [email protected] accepted by 192.168.1.2:25 (mx.example.com)",
However, if I send the message using SMTP, it adds the from IP as expected "details": "Message for [email protected] accepted by 192.168.1.2:25 (mx.example.com) (from 172.16.1.5)",
The issue seems to come from the fact that it only appends the IP address "if @current_endpoint.smtp_client.source_address r.output = smtp_result.string"
smtp_sender.rb
def send_message_to_smtp_client(raw_message, mail_from, rcpt_to, retry_on_connection_error: true)
start_time = Time.now
smtp_result = @current_endpoint.send_message(raw_message, mail_from, [rcpt_to])
logger.info "Accepted by #{@current_endpoint} for #{rcpt_to}"
create_result("Sent", start_time) do |r|
r.details = "Message for #{rcpt_to} accepted by #{@current_endpoint}"
r.details += " (from #{@current_endpoint.smtp_client.source_address})" if @current_endpoint.smtp_client.source_address
r.output = smtp_result.string
end
It looks like (and this is just my guess, I don't actually know) the code was put there with the assumption that it will only have an smtp source_address to use from the SMTP client sending the message through Postal, but the IP address reported in the message details is in fact the Postal sending IP I'm expecting and not the IP of my device sending to Postal with SMTP.
Is there a reason the if statement has to be there, and if not, can the IP address always be appended to the message details so that there is an easy way to determine the sending IP through webhooks?
I'm using Postal 3.3.2
The source address is only present in the log when using the IP pools functionality. If you aren't using this, the mail will be sent from the IP address on the server itself and is outside of the Postal's control.
If you'd like to appear, you can enable IP pools đ
I actually do have IP pools enabled.
The IP seems to conditionally appear based on how I give the message to Postal. If I send the message through the UI, the IP does show up. If I send through my SMTP credential, the IP does show up. If I use the raw API endpoint, the IP does not show up.
Is there a reason it shouldnât show up just because it was sent with the API?
Okay, I found my issue. If a sending domain doesnât have a rule to map it to an IP pool, it wonât show an IP. My SMTP sender was specifying a different address which did map to a rule.
Interestingly, I just changed the Postal mail serverâs default IP pool, and then changed it back, and now the IP is showing for that address even though it doesnât map to a rule. đ¤ˇââď¸
Iâve always noticed some âslightlyâ strange behavior with the default IP pool when the default IP pool is automatically chosen by Postal rather than being manually specified, but as soon as I specify the IP pool, all that slight weirdness goes away so itâs not really a problem.
Sorry for any confusion I may have caused and thank you for all the great work you do! It is really appreciated.