How it works...

Step 1 imports the requests module to be used later. The credentials and the basic information in the message are defined in step 2, and should be extracted from the Mailgun web interface, as shown before.

Step 3 defines the email that will be sent. Step 4 structures the information in the way Mailgun expects. Notice the html and text fields. By default, it will set HTML as preferred and the plain-text option as an alternative. The format for the TO and FROM should be in the Name <address> format. You can use commas to separate multiple recipients in TO.

The call to the API  is made in step 5. It is a POST call to the messages endpoint. The data is transferred in the standard way, and basic authentication is used with the auth parameter. Notice the definition in step 2. All calls to Mailgun should include this parameter. It returns a message notifying you that it was successful and the message is queued.

In step 6, a call to retrieve the events through a GET request is made. This will show the latest actions performed, the last of which will be the recent send. Information about delivery can also be found.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.205.139