简体   繁体   中英

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?

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='alice@example.com' \
    -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='alice@example.com' \
    -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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM