farfer
farfer

Reputation: 31

Is there a way to trace IP address from where mailgun API is called

We are using Mailgun for email sending with Laravel and currently facing issues regarding the email being sent daily. There are four instances of sites and unable to track from where the emails are being sent out.

So is there any way we can trace IP address from where the Mailgun API is calling?

Upvotes: 1

Views: 1207

Answers (1)

Daniel W.
Daniel W.

Reputation: 32290

Adding a custom header to mailgun emails

The best way in my opinion is to mark the mails with a custom header using h: option:

curl -s --user 'api:YOUR_API_KEY' \
    https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages \
    -F from='Sender Bob <sbob@YOUR_DOMAIN_NAME>' \
    -F to='[email protected]' \
    -F subject='Hello' \
    -F text='Testing some Mailgun awesomness!' \
    -F h:X-Sender-Reference='server3'

This way, you can see in the event log the X-Sender-Reference custom header to know which server sent the message.

Keep in mind, these headers can be viewed by thee receiver aswell so do not expose sensitive information.

Depending on your library, something like this can be used:

$headers = $message->getHeaders();
$headers->addTextHeader('X-Sender-Reference', 'server3');

See: https://documentation.mailgun.com/en/latest/api-sending.html#sending

Tagging a mailgun email message

There is also the option to tag a message using o::

curl -s --user 'api:YOUR_API_KEY' \
    https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages \
    -F from='Sender Bob <sbob@YOUR_DOMAIN_NAME>' \
    -F to='[email protected]' \
    -F subject='Hello' \
    -F text='Testing some Mailgun awesomness!' \
    -F o:tag='September newsletter' \
    -F o:tag='server3'

The allowed tags per message are limited to three and the purpose are marketing aggregations I think. Technically, it is possible to use it the same way as the custom header in the example above.

Some PHP libraries might be used this way:

$headers = $message->getHeaders();
$headers->addTextHeader('X-Mailgun-Tag', 'server3');

See: https://documentation.mailgun.com/en/latest/user_manual.html#tagging

Upvotes: 1

Related Questions