Sending email using mailgun

What should i type in sender_email…??? Because i got reading from the sensor; but i can’t received email …

SENDER_EMAIL = ‘This would be test@your SANDBOX_URL’

if you are using mailgun the you shall have a Sandbox url
just write that url after @ as mentoined above

I didn’t received any email…from mailgun.
How to fix it???

Did you check your spam?

Yes…there is no mail regarding mailgun…

did you mean account conformation email or the triggered email

Triggered email…i got readings from sensor but didn’t received email…

is your code working
if your code is working then wait for sometime it may take a bit

You didnt get any error after executing? The mail will be sent only if the “if” condition in your code is true. Pls do provide the screenshot of your code.

Did you add your email under Authorized Recipients.
If you have then you will receive a mail asking you to agree to receive mails.
You will Have to agree to receive mail from mailgun.
Hope this helps

Yes…i added my E-mail under authorized recipients and also received a mail asking about to agree to receive mails.
but still i didn’t receive mails after the execution of program.

It is due to incorrect credentials in file. Check this link:

this coding seems correct. Verify your credentials given in email_conf(it should be ideally correct as there were no errors while executing and also the Mailgun Logs. Errors in sending the alert will be given in the logs.
I hope you got the senders email correct. If everything goes correctly, you should receive the mail in the given recipient mail id.
Try changing your limits…say 400 as minimum and 500 as max…or if with your values, try keeping something cold from freezer on the sensor.

Do send the screenshot after execution of your code.

Just follow these steps to get it working, I have even attached some screenshots for reference.

Getting details required to send E-mails :

1. Log In to your mailgun account.

2.Click your DP ( display Picture ) at the top right corner, after that a drop down menu occurs. In that click “Switch to classic UI”.


3.Then Scroll all the way to the bottom of the page. You will find Sandbox Domains in that click " Authorised Recipients " .

4.Then Click “Invite New Recipient” .

5.Add your email ID to which you want to receive email from bolt module.


# IMP # After inviting (by clicking Invite Recipient) you have to login to your email ID . You will receive a mail from mailgun to confirm your email ID to receive mail from mailgun. So confirm that.


6.Now at the top menu bar beside( on the right of ) the mailgun logo click Domains.

After that click your domain name < check the long red rectangle with round corners in the below image_ >

7.Then a new web page appears with your Domain information and your API Key and many more details.

NOTE the following details :

Your Sandbox url is your domain name. < Shown in blue box in below image >
Your API key is given in the red box in below image.

So keep a note of that.

For sending E-Mails :

After the above details are obtained. Now, In your or any other python file where you store all your access information’s such as Bolt API key, etc, there add your mail gun info

  1. mailgun API key : < Located in above step 7 image - red box >
  2. sandbox URL : < Located in above step 7 image - blue box >
  3. senders email : < Refer below image >
  4. recipient email : < Email Id that you invited in step 5 above >

After that, In your main python project file where you collect and process data received from bolt device. Firstly import necessary modules. Then, creating a mail sender object called “mailer” ( refer image attached below ) so that we can send E-Mails:

For sending an email to the registered email ID ( refer image attached below ), we use the send_email function of the mailer object [ mailer.send_email( “subject”, “Body” ) ] :


So...yea by following the above steps an email with the specified content will be sent to the registered email ID, to receive the alert email it may take few minutes. So be patient !


In case if there is any improvement or any steps that are not mentioned here and need to be added please let me know.
And, If you like the post a Thumbs Up would be appreciated. :+1: :smile:

Happy learning !

Note: The above sandbox URL is made up, and is for giving an example only.


Yahh… Finally i received email regarding temperature alert…thanks to all of you for helping…

I have my email ID in the authorized recipients. I created a python file with the following code

import requests
def send_simple_message():
auth=(“api”, “0939da33c77f2668afbf9e7aee005a1a-c50f4##”),
data={“from”: “Excited User”,
“to”: [“my email ID”],
“subject”: “Hello”,
“text”: “Testing some Mailgun awesomness!”})

And i just executed it by python3 But no email recieved.
P.S. I have installed the requests library

Assuming the " # " is replaced by your actual api key and domain name.

Now try writing your " from address " as it is given in the below code.
and keep this in mind,

  1. YOUR_DOMAIN_NAME = your

  2. REPLACE -> " " with your authorized recipient.



So…yea just let me know after trying if it works!

there is no “classic UI” option as per step 2