I try to send email via python using Mailgun
I have
def send_simple_message():
return requests.post(
"https://api.mailgun.net/v3/sandbox6247218655a94010b9840c23c2688fc7.mailgun.org",
auth=("api", "key-********"),
data={"from": "Excited User <bb@gmail.com>",
"to": ["bb@outlook.com", "bb4@gmail.com"],
"subject": "Hello",
"text": "Testing some Mailgun awesomness!"})
I realize I forgot /messages
def send_simple_message():
return requests.post(
"https://api.mailgun.net/v3/sandbox6247218655a94010b9840c23c2688fc7.mailgun.org/messages",
auth=("api", "key-********"),
data={"from": "Excited User <bb@gmail.com>",
"to": ["bb@outlook.com", "bb4@gmail.com"],
"subject": "Hello",
"text": "Testing some Mailgun awesomness!"})
I run it
python mail.py
I still don't see any email. I also check my MailGun and my spam folder.
Any hints for me ?
Avoiding to the MailGun documentation , here you can see that the POST url should be in this format https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages
From your piece of code, I can see that sandbox6247218655a94010b9840c23c2688fc7.mailgun.org
is YOUR_DOMAIN_NAME
but your missing the format which is the /messages
API endpoint.
So all you have to do is to add the /messages
endpoint to your post URL. So it changes from https://api.mailgun.net/v3/sandbox6247218655a94010b9840c23c2688fc7.mailgun.org
to https://api.mailgun.net/v3/sandbox6247218655a94010b9840c23c2688fc7.mailgun.org/messages
.
Update: I skipped that part, yes you don't see any mail from your inbox due to the fact that you're trying to send the email on behalf of GMail. You can send emails on behalf of and ONLY from the domain you've registered.
Thats it!
Also note that if your domain is added to the EU region (instead of US) you have to change the post URL domain from api.mailgun.net
to api.eu.mailgun.net
(note the .eu
), as read in the documentation .
So the entire URL would be https://api.eu.mailgun.net/v3/YOUR_DOMAIN_NAME/messages
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.