here i am getting this attribute error. what’s the problem here i had check my API key twice it’s absolutely fine.
It says that you didn’t initialize the email_conf file.
Once check your command and files which you had listed.
It seems that you are not getting the json response from the send_email function because of some invalid details that you have passed in the line
mailer = Email(email_conf.MAILGUN_API_KEY, email_conf.SANDBOX_URL, email_conf.SENDER_EMAIL, email_conf.RECIPIENT_EMAIL)
Remove the below line from your code
response_text = json.loads(response.text) print("Response received from Mailgun is: " + str(response_text['message']))
and directly print the response without doing json.loads()
print ("Mailgun response is " + response.text)
Also, print the credentials before passing to Email.
Check the below code snippet.
import email_conf, json, time from boltiot import Email, Bolt 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) print(email_conf.MAILGUN_API_KEY) print(email_conf.SANDBOX_URL) print(email_conf.SENDER_EMAIL) print(email_conf.RECIPIENT_EMAIL) 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)) print ("Mailgun response is " + response.text) except Exception as e: print ("Error occured: Below are the details") print (e) time.sleep(10)
This error generally occurs in the case of invalid sender domains.
Can you please check the sender email that you must have added to the config file?
will you tell me which email i have to put in place of sender email id?
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’
The above format is the Conf file.
In your Mailgun Dashboard, you will find the SANDBOX URL.
error comes because of error in your email_conf file
Do follow the below link to rectify and also check for the uppercase and lower case of all the API key and sandbox URL:
Maligun mail not send
For the MAILGUN_API_KEY,
On dashboard-> Click on the sandbox link at the bottom-> You’ll be directed to the Overview page, click on the select button on the API tab, now select Python language and copy the API Key
In the API base URL, Copy the part from where “sandbox” starts
test@Same as SANDBOX_URL
Enter the email which you have verified as the Authorized recipient on Mailgun
API_KEY and DEVICE_ID you already know from earlier projects.