mail.smtp

mail.smtp

class platypush.plugins.mail.smtp.MailSmtpPlugin(server: Optional[str] = None, port: Optional[int] = None, local_hostname: Optional[str] = None, source_address: Optional[List[str]] = None, username: Optional[str] = None, password: Optional[str] = None, password_cmd: Optional[str] = None, access_token: Optional[str] = None, oauth_mechanism: Optional[str] = 'XOAUTH2', oauth_vendor: Optional[str] = None, ssl: bool = False, keyfile: Optional[str] = None, certfile: Optional[str] = None, timeout: Optional[int] = 60, **kwargs)[source]

Plugin to interact with a mail server over SMTP.

__init__(server: Optional[str] = None, port: Optional[int] = None, local_hostname: Optional[str] = None, source_address: Optional[List[str]] = None, username: Optional[str] = None, password: Optional[str] = None, password_cmd: Optional[str] = None, access_token: Optional[str] = None, oauth_mechanism: Optional[str] = 'XOAUTH2', oauth_vendor: Optional[str] = None, ssl: bool = False, keyfile: Optional[str] = None, certfile: Optional[str] = None, timeout: Optional[int] = 60, **kwargs)[source]
Parameters:
  • server – Server name/address.

  • port – Port (default: 25 for plain, 465 for SSL).

  • local_hostname – If specified, local_hostname is used as the FQDN of the local host in the HELO/EHLO command. Otherwise, the local hostname is found using socket.getfqdn().

  • source_address – The optional source_address parameter allows binding to some specific source address in a machine with multiple network interfaces, and/or to some specific source TCP port. It takes a 2-tuple (host, port), for the socket to bind to as its source address before connecting. If omitted (or if host or port are ‘’ and/or 0 respectively) the OS default behavior will be used.

  • username – SMTP username.

  • password – SMTP password.

  • password_cmd – If you don’t want to input your password in the configuration, run this command to fetch or decrypt the password.

  • access_token – OAuth2 access token if the server supports OAuth authentication.

  • oauth_mechanism – OAuth2 mechanism (default: XOAUTH2).

  • oauth_vendor – OAuth2 vendor (default: None).

  • ssl – Use SSL (default: False).

  • keyfile – Private key file for SSL connection if client authentication is required.

  • certfile – SSL certificate file or chain.

  • timeout – Server connect/read timeout in seconds (default: 60).

send(to: Union[str, List[str]], from_: Optional[str] = None, cc: Optional[Union[str, List[str]]] = None, bcc: Optional[Union[str, List[str]]] = None, subject: str = '', body: str = '', body_type: str = 'plain', attachments: Optional[List[str]] = None, headers: Optional[Dict[str, str]] = None, **connect_args)

Send an email through the specified SMTP sender.

Parameters:
  • to – Receiver(s), as comma-separated strings or list.

  • from – Sender email address (from is also supported outside of Python contexts).

  • cc – Carbon-copy addresses, as comma-separated strings or list

  • bcc – Blind carbon-copy addresses, as comma-separated strings or list

  • subject – Mail subject.

  • body – Mail body.

  • body_type – Mail body type, as a subtype of text/ (e.g. html) (default: plain).

  • attachments – List of attachment files to send.

  • headers – Key-value map of headers to be added.

  • connect_args – Parameters for .connect(), if you want to override the default server configuration.