hey comm,
this is a solution on how to send emails through actions
#dont forget the other imports
import smtplib
class Sendmail(Action):
def name(self) -> Text: return "action_send_mail"
def run(self, dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
Subject = tracker.get_slot('Subject')
Body = tracker.get_slot('Body')
Recipient = tracker.get_slot('Recipient')
server = smtplib.SMTP_SSL('smtp.gmail.com', 465) #connect to smtp server
server.login("sender@gmail.com", "sender_pswd")
# you can write your mail and or get it from the slots with tracker.get_slot
# if you are using your email is better that you dont pass it through the code for security u can
# set path variables with email and password and use them instead
msg ="Subject: {} \n\n {} " .format(Subject,Body) #creating the message
server.sendmail( #send the email
"sender@gmail.com",
Recipient,
msg)
server.quit()
dispatcher.utter_message(" Email sended ! ")
return [SlotSet("to",Recipient)] #just in my case, u can return ntg