Sending email through action

hey comm,

this is a solution on how to send emails through actions :slight_smile:

#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

can you share what should be written in domain.yml?

@Youssef-0

hey @Akhil1278

really sorry for my late repy,
and about my domain file i just define the entities and slots that we need in this case w need
entities : Subject, Body, Recipient
and slots with the same names of entities
and finally you need to mention the name action we are working on in action
and finally provide atleast a story to work with :slight_smile:
am sorry but i lost the domain file of this example … let me know if you need smtg else hope that would help.

@Youssef-0 can you please share code to send email through email

hey @vishal4000 i already shared the code take a look :point_up_2: :point_up_2:

please share the code along with domain, stories

hey @maksudcs really sorry for my late reply let me know if you still need help :slight_smile:

please share a complete domain, nlu, stories, rules, and actions files if you can. many thanks in advance.