Problem with temperature sensor alert ( Email )



pls see see above images carefully. I was working in Replit. and using windows 7 ultimate computer.
I was trying to build a temperature alert system. via email. which is given in the bolt training.
however the code is not working and when I press run, It is staying blank.
pls assist me in this. your knowledge and experience will be greatly acknowledged .

Hi @prithwis1201

Please rename your temp_email.py file to main.py . This should fix the issue. Please try this and let us know if you get any issue.

1 Like

Ok I will try and inform you of the outcome

@sneharsh.kerkar
Hi there !
the code is working ! thanks for that but still it is showing an error . I have provided the screenshot below, pls look at it carefully and solve my problem. pls.
your knowledge and experience will be greatly acknowledged.

Thank you .

Hi @prithwis1201

Please make sure that you specify the credentials correctly in the email_conf.py file. Also do checkout the below code incase you have made any logical errors in the code.
Do try this and let me know if it works.

import email_conf
from boltiot import Email, Bolt
import json, time

minimum_limit = 400 #the minimum threshold of light value 
maximum_limit = 600 #the maximum threshold of light value 


mybolt = Bolt(email_conf.API_KEY, email_conf.DEVICE_ID)
mailer = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOX_URL, email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL)


while True: 
    print ("Reading sensor value")
    response = mybolt.analogRead('A0') 
    data = json.loads(response) 
    print ("Sensor value is: " + str(data['value']))
    try: 
        sensor_value = int(data['value']) 
        if sensor_value > maximum_limit or sensor_value < minimum_limit:
            print("Making request to Mailgun to send an email")
            response = mailer.send_email("Alert", "The Current temperature sensor value is " +str(sensor_value))
            response_text = json.loads(response.text)
            print("Response received from Mailgun is: " + str(response_text['message']))
    except Exception as e: 
        print ("Error occured: Below are the details")
        print (e)
    time.sleep(10)


hi there @sneharsh.kerkar
I had copied the exact code that you posted and pasted it on to replit, but still it is not working, I had also checked the email_conf.py and saw that all the credentials were correctly entered I have provided you with the screenshot of the screen. pls see it carefully, and solve my problem. your knowledge and wisdom will be greatly acknowledged.

Hi @prithwis1201

Please try to put print statement below json.loads(response.text) line and see what output you are getting. This way you will know where exactly the issue is

print("Response:", response.text )

Also please share you entire code with me and also share a screenshot of email_conf file to support@boltiot.com as it has your credentials. This will help us to verify the code and the credentials and resolve the issue.

Hi There @sneharsh.kerkar
I have done as you have told me to do , but still it is not working I am sending you the screenshot of my whole code and email_conf.py on the email address : support@boltiot.com please , do check it out and help me on this issue. :neutral_face: :neutral_face: :neutral_face: :neutral_face: :neutral_face:

Hi @prithwis1201

I have reviewed the screenshots you have sent via email and I see that the mailgun API in your email_conf.py file is incorrect. The mail gun API should be a long key ( almost 50 characters) and is generated only once when you create the API key in mailgun, so you have to copy and store it somewhere safe .
In your case I assume you did not back up the long api key which was generated while creating it.

To solve this issue, you can create a new API Key and take a backup of that. Then you can use that api key in your project. Kindly follow these steps:

  • Go to your mailgun dashboard
  • On the top right click on your profile
  • Go to API setting
  • At the bottom, there will be a section mailgun api keys, click on ADD NEW KEY. Give the key a name and click on Create Key.
  • A long key will be generate, please copy and backup this (important)

This is how the api key window looks on mailgun

Please do try this and let us know. If you still face any issues please feel free to get back to us

Hi @sneharsh.kerkar
I have made the changes as you told me. I now have to add my Email to authorized recipient
in mailgun. but I am not able to find the option to add it. can you kindly provide a screenshot of the location of the (add authorized recipients button). I will be very grateful to you. Thank you

Hi @prithwis1201

To add authorized recipient, follow these steps:

  • Log in to your mailgun dashboard
  • On the left hand sidebar, click on Sending → Domains
  • You long sandbox url will be displayed under the domains panel. Click on the sandbox url
  • Scroll down and you will get a box to enter the authorized recipient email. Enter that here

If you still face any issues, please feel free to get back to us.

Hi There @sneharsh.kerkar
Thank you very much. The code is working perfectly fine. But still there are some issues.
pls see the screenshots given below carefully.




Even though in Replit and mailgun Dashboard , it is showing that it is accepted, delivered and request was successful, yet I cannot see any such E mail in my inbox in Gmail. I have also checked the spam and trash sections. yet there is no sign of it being delivered to me . pls, do look into the matter and inform me that what the hell is wrong !

Thank You ,
Bolt User,
Prithwis Dutta

Hi @prithwis1201

Please cross check the email id you have provided to mailgun for sending the emails. Please let us know if you still face the issue.

Hi there @sneharsh.kerkar
I have Cross-checked my email, but still It is not working. In my Gmail still the email has not come. please help me in this issue. If you say, I will provide my email address and my password to you personally in your email. :neutral_face: :neutral_face: :neutral_face: :neutral_face: :neutral_face: :neutral_face:

Thank you,
Bolt User,
Prithwis Dutta

Hi @prithwis1201

Please check your email logs in mailgun to verify if email is sent or not. To check the log follow these steps:

  • Log in to Mailgun dashboard
  • on left hand side, click on sending
  • click on logs
  • on top right dropdown select your sandbox url. All the email logs will displayed which have been sent for that particular sandbox url.

Please verify this and get back to us if you face any issue.

Hi There @sneharsh.kerkar
Here are the screenshots where you had asked me to check. pls see that no activity is being shown .Pls provide a solution and tell me what the hell is wrong


Hi There @sneharsh.kerkar
Here are the screenshots for which you asked me.




Hi @prithwis1201

As discussed on call, please go to the mailgun logs, below the graph and send us the screenshot of the detailed logs below the graph

Alternatively you can try with different email id to rectify whether the issue is with your mail or mailgun.

do try this and let me know

Here is the image of the detailed logs for which you asked for

I had tried this with my mother’s email id and it is working perfectly fine now.
only just that I found the Email in the spam folder. But , no worries.
I think that since I am a 13 year old and there is still parental controls enabled on my Email id. Ok , anyways. thank you for your patience and gratitude I am very grateful to you. Ok thank you .Bye.
I’ll notify you if I have any future issues

Bolt user,
Prithwis Dutta.