import smtplib
      import logging
      
      def send_email(server_host, server_port, server_username, server_password, fromaddr, toaddrs, messsage):
        """
        Send an email using SMTLlib
        :param server_host: host of the server to send email from
        :param server_port: port to connect to
        :param server_username: username to authenticate to the server
        :param server_password: password to authenticate to
        :param fromaddr: The email use for the From:
        :param toaddrs: all recipinents
        :param message: message to send
        """
        try:
          server = smtplib.SMTP(server_host, int(server_port))
          server.ehlo()
          if use_tls:
            server.starttls()
           server.ehlo()
           server.login(server_username, server_password)
      
           server.sendmail(fromaddr, toaddrs, message)
           server.quit()
       except smtplib.SMTPServerDisconnected:
         logging.exception("Cannot send email to %s", toaddrs)

      Python language logo
      Send email with SMTPlib

      email
      Python public recipes

      Basic email sending with smtplib

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.