Mailgun api key is not shown above the python code

I tried sendings → overview → scrolling down i found api keys → it shows public key and http webhook key, i tried both in my code but it shows error like expecting value: line1 colum1 (char 0).

Hi @223j5a4205

Could you please elaborate more on the issue you are facing? Alternatively please do share the screeshots or code snippet. This will enable us to guide you correctly.

Hi @223j5a4205

Please make sure that you have given the correct credentials in your email_conf.py file. Enter the correct mailgun api, sandbox url, sender email, recipient email, Bolt api key and bolt device id in the email_conf.py file.

Below is a working code for temperature email alert. Do try this. Make sure to replace the api keys and other credentials with your actual credentials

main.py file:

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

minimum_limit = 300 #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)

email_conf.py file: please replace the content inside the quotes (’ ') with your values.

MAILGUN_API_KEY = 'This is the private API key which you can find on your Mailgun Dashboard' 
SANDBOX_URL= 'You can find this on your Mailgun Dashboard' 
SENDER_EMAIL = 'test@' + SANDBOX_URL  # No need to modify this. The sandbox URL is of the format test@YOUR_SANDBOX_URL
RECIPIENT_EMAIL = 'Enter your Email ID Here'
API_KEY = 'This is your Bolt Cloud account API key'
DEVICE_ID = 'This is the ID of your Bolt device'

Do try this and let us know. If you still face any issue, please feel free to get beck to us.

I could not find any mailgun api key here

I got the solution, i created a new api key and then copy the api key to my code and then the code works

Thank you for guiding me @sneharsh.kerkar

1 Like