import speech_recognition as sp
import smtplib
import pyttsx3
from email.message import EmailMessage
listener = sp.Recognizer()
speak = pyttsx3.init()
def talk(text) :
speak.say(text)
speak.runAndWait()
def command ():
try:
with sp.Microphone() as source :
print("listening ...")
voice = listener.listen(source)
text = listener.recognize_google(voice)
print(text)
return text.lower()
except:
pass
def send(receiver,subject,body):
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login("asbedi2004@gmail.com","xxxxxxxx")
email = EmailMessage()
email["From "] = "asbedi2004@gmail.com"
email["To"] = receiver
email["Subject"] = subject
email.set_content(body)
server.send_message(email)
email_list = {"angad" : "angadsb4069@gmail.com"}
def email_info():
talk("Who do you want to send the email to ?")
recipient = command()
receiver = email_list[recipient]
talk("What is the subject of the email?")
subject = command()
talk("What is the body of the email?")
body = command()
send(receiver , subject , body)
talk("Hey you good for nothing lazy , your email has been sent")
talk("Do you want to send another email")
send_again = command()
if "yes" in send_again:
email_info()
email_info()
i have allowed the less secure app access on the gmail meanage setting. I have also checked the email id and the password, they are correct!
here is the error:
listening ... Angad listening ... code not working listening ... someone please help me with this code it is not working it shows this error
Traceback (most recent call last):
File "/Users/angadsinghbedi/Desktop/PycharmProject/email_bot/email_bot.py", line 58, in <module>
email_info()
File "/Users/angadsinghbedi/Desktop/PycharmProject/email_bot/email_bot.py", line 50, in email_info
send(receiver , subject , body)
File "/Users/angadsinghbedi/Desktop/PycharmProject/email_bot/email_bot.py", line 33, in send
server.send_message(email)
File "/Users/angadsinghbedi/.pyenv/versions/3.6.0/lib/python3.6/smtplib.py", line 947, in send_message
''.join([from_addr, *to_addrs]).encode('ascii')
TypeError: sequence item 0: expected str instance, NoneType found