Trying to run a very simple python program for test. Following is the code:
import requests
def send_email():
files = [
('to', '<my-email-address>'),
('subject', 'Thank you from Foo'),
('text', 'Hello World'),
('from', '\"Info\" <[email protected]>'),
]
r =requests.post('https://api.mailgun.net/v3/mail1.parkl.com/messages', files=files, auth=('api', '<my-key>'))
print r.text, r.status_code
if __name__ == "__main__":
send_email()
It spits out { "message": "'from' parameter is not a valid address. please check documentation" } 400
I have tried various option for From parameter but none seem to work. "Info" , [email protected], [email protected]
Reading online it seems I am not the first one running into this issue but could someone point me how to fix this and move ahead.
A curl request with exact same parameter just works fine:
curl -s —user 'api:<my-key>' \
https://api.mailgun.net/v3/mail1.parkl.com/messages \
-F from=‘Foo <[email protected]>' \
-F to=<my-email-address> \
-F subject='Info Hello' \
-F text='Testing some Mailgun awesomness!'
Escape characters would not be required in the value for From parameter when specifying a display name. Though, you could use double quote for the display name like so:
import requests
def send_simple_message():
return requests.post(
"https://api.mailgun.net/v3/example.com/messages",
auth=("api", "key-<api-key-here>"),
data={"from": '"Excited User" <[email protected]>',
"to": "[email protected]",
"subject": "Hello",
"text": "Testing some Mailgun Awesomeness!"})
print send_simple_message().text
Or set the value for the From parameter in single or double quotes such as:
"from": 'Excited User <[email protected]>'
** Disclaimer I work at Mailgun **
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With