I'm integrating Mailjet into my Google App Engine application. I'm at the point where I can successfully send email from the local development server. But when I deploy my application and try to send an email, the Mailjet client library apparently hits an error when trying to connect to the Mailjet rest API.
Caused by NewConnectionError(': Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'
I basically followed instructions from
https://cloud.google.com/appengine/docs/standard/python/mail/sending-messages
and
https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27
Code I added to integrate mailjet.
requirements.txt:
certifi==2019.6.16
chardet==3.0.4
idna==2.8
mailjet-rest==1.3.3
requests==2.22.0
urllib3==1.25.3
app.yaml:
...
libraries:
- name: ssl
version: latest
main.py:
from mailjet_rest import Client
...
#calling this function to send email
def mailjet_sendmail(to_address, subject, body):
api_key = '***'
api_secret = '***'
mailjet = Client(auth=(api_key, api_secret), version='v3.1')
data = {
'Messages': [
{
"From": {
"Email": "noreply@mydomain.com",
"Name": "mydomain.com"
},
"To": [
{
"Email": to_address,
}
],
"Subject": subject,
"TextPart": body,
}
]
}
result = mailjet.send.create(data=data)
When I call mailjet.send.create, the following exception shows in the error logs:
ApiError: HTTPSConnectionPool(host='api.eu.mailjet.com', port=443): Max retries exceeded with url: /v3.1/send (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x2a66ef5e1950>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))
at api_call (/base/data/home/apps/s~***/20190828t114640.420634513089712020/mailjet_rest/client.py:110)
at create (/base/data/home/apps/s~***/20190828t114640.420634513089712020/mailjet_rest/client.py:62)
at mailjet_sendmail (/base/data/home/apps/s~***/20190828t114640.420634513089712020/main.py:80)
at post (/base/data/home/apps/s~***/20190828t114640.420634513089712020/main.py:379)
...
It looks as if it fails to resolve api.eu.mailjet.com.
Is there anything I need to do to enable DNS lookup in Google App Engine? Can someone show a fully working example?
Note that exactly the same code works on my PC running the local development server.
Thanks
Fred