How to use the aiosmtpd.controller.Controller function in aiosmtpd

To help you get started, we’ve selected a few aiosmtpd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lindsay-stevens / limesurveyrc2api / tests / utils.py View on Github external
def __init__(self):
        self.messages = []
        self.handler = CapturingAiosmtpdHandler(context=self)
        self.controller = Controller(
            handler=self.handler, hostname="localhost", port=10025)
github shantanugoel / email-actions / email_actions / server.py View on Github external
from email_actions.config import check_config


def bind(family, type, proto):
  """Create (or recreate) the actual socket object."""
  sock = socket.socket(family, type, proto)
  sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)

  # If listening on IPv6, activate dual-stack.
  if family == socket.AF_INET6:
    sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, False)

  return sock


class EAController(Controller):
  def make_socket(self):
    host = self.hostname
    port = self.port
    try:
      # First try to determine the socket type.
        info = socket.getaddrinfo(
          host, port,
          socket.AF_UNSPEC,
          socket.SOCK_STREAM,
          0,
          socket.AI_PASSIVE,
        )
    except socket.gaierror:
      # Infer the type from the host.
        addr = host, port
        if ':' in host:
github scrapbird / sarlacc / smtpd / src / mailer.py View on Github external
async def create_mailer(handler, loop, ident_hostname, ident, **kwargs):
    """Creates and initializes a ``Mailer`` object

    Args:
        loop -- asyncio loop.
        ident_hostname -- the hostname to use in the ident message.
        ident -- the version string.

    Returns:
        The Mailer object.
    """

    return Mailer(handler, loop, ident_hostname, ident, **kwargs)


class CustomIdentController(Controller):
    def __init__(self, handler, loop, ident_hostname, ident, **kwargs):
        """Init method for ``CustomIdentController``.

        Args:
            handler -- the smtpd MailHandler object.
            loop -- the asyncio loop.
            ident_hostname -- the hostname to use in the ident message.
            ident -- the version string.
        """

        self.loop = loop
        self.ident_hostname = ident_hostname
        self.ident = ident
        super(CustomIdentController, self).__init__(handler, loop=loop, **kwargs)

    def factory(self):
github kz26 / mailproxy / mailproxy.py View on Github external
if not os.path.exists(config_path):
        raise Exception("Config file not found: {}".format(config_path))

    config = configparser.ConfigParser()
    config.read(config_path)
    
    use_auth = config.getboolean('remote', 'smtp_auth', fallback=False)
    if use_auth:
        auth = {
            'user': config.get('remote', 'smtp_auth_user'),
            'password': config.get('remote', 'smtp_auth_password')
        }
    else:
        auth = None
    
    controller = Controller(
        MailProxyHandler(
            host=config.get('remote', 'host'),
            port=config.getint('remote', 'port', fallback=25),
            auth=auth,
            use_ssl=config.getboolean('remote', 'use_ssl',fallback=False),
            starttls=config.getboolean('remote', 'starttls',fallback=False),
        ),
        hostname=config.get('local', 'host', fallback='127.0.0.1'),
        port=config.getint('local', 'port', fallback=25)
    )
    controller.start()
    while controller.loop.is_running():
        sleep(0.2)