Mailgun provides one of the nicest APIs for email communication.
This example assumes we have a mailing list already created and want to send an email to all recipients via the Mailgun API.
The way to do this is to POST to /messages and use the mailing list address as the recipient address in the API call. Here is the call being made via cURL:
$ curl --request POST \ --url https://api:MY_API_KEY@api.mailgun.net/v3/mg.mydomain.com/messages \ --form 'from=Name <noreply@mg.mydomain.com>' \ --form "text=My email body" \ --form "subject=My email subject line" \ --form to=my-email-list@mg.mydomain.com \ --form user=api:MY_API_KEY
Note that this API call uses form fields and not any JSON payload.
A successful response will look something like:
{ "message": "Queued. Thank you.", "id": "..." }
References