Skip to main content

A user-friendly Python email toolkit

Project description

A user-friendly Python email toolkit

Installation

python3 -m pip install mailkit

Usage on CMD

Usage: python -m mailkit.bin.main [OPTIONS] COMMAND [ARGS]...

  A user-friendly Python email toolkit

Options:
  --version              Show the version and exit.
  -H, --host TEXT        SMTP server hostname or IP address
  -P, --port INTEGER     SMTP server port
  -u, --username TEXT    SMTP server username
  -p, --password TEXT    SMTP server password
  -s, --use-ssl BOOLEAN  Use SSL connection  [default: True]
  -t, --timeout INTEGER  SMTP server timeout  [default: 10]
  -e, --env-file TEXT    The environment file to load  [default: ~/.mailkit.env]
  -h, -?, --help         Show this message and exit.

Commands:
  config  initialize the configuration file
  send    send email to user(s)

mailkit config

mailkit config

# flowing the instruction to complete the configuration
"
>>> SMTP host: smtp.exmail.qq.com
>>> SMTP port [465]: 
>>> SMTP username: suqingdong@novogene.com
>>> SMTP password: 
>>> SMTP use ssl [True]: 
>>> SMTP timeout [10]: 
login success.
Saved configuration to ~/.mailkit.env
"

# you can also use envernment variables
export SMTP_HOST=smtp.gmail.com
export SMTP_PORT=465
export SMTP_USERNAME=suqingdong@gmail.com
export SMTP_PASSWORD=YOUR_PASSWORD
export SMTP_USE_SSL=True
export SMTP_TIMEOUT=10

mailkit send

Usage: python -m mailkit.bin.main send [OPTIONS]

  send email to user(s)

Options:
  -f, --from-addr TEXT     the display address of the sender, default is the login username
  -t, --to-addrs TEXT      the recipient address(es)  [required]
  -s, --subject TEXT       the subject of the email  [required]
  -b, --body TEXT          the body of the email
  -a, --attachments TEXT   the attachments of the email
  -C, --charset TEXT       the charset of the email  [default: utf-8]
  -c, --content-type TEXT  the content type of the email, eg.: plain, html [default: plain]
  -cc, --cc TEXT           the cc address(es)
  -bcc, --bcc TEXT         the bcc address(es)
  -h, -?, --help           Show this message and exit.


# Examples:

# basic usage
mailkit send -t "to@example.com" -s "subject" -b "body"

# use charset
mailkit send -t "to@example.com" -s "subject" -b "body" -C "gbk"

# use content-type
mailkit send -t "to@example.com" -s "subject" -b "<h1>body</h1>" -C "utf-8" -c "html"

# use cc and bcc
mailkit send -t "to@example.com" -s "subject" -b "body" -cc "cc@example.com" -bcc "bcc@example.com"

# use attachments
mailkit send -t "to@example.com" -s "subject" -b "body" -a "attachment.txt"

# multiple parameters
mailkit send -t "to_1@example.com" -t "to_2@example.com" -s "subject" -b "body" -a "attachment.txt" -a "attachment_2.txt"

# auth with parameters
mailkit -H smtp.gmail.com -u username@gmail.com -p password send -t "to@example.com" -s "subject" -b "body"

# auth with an env_file
mailkit -e .env send -t "to@example.com" -s "subject" -b "body"

Usage in Python

from mailkit.core import SendEmail

mail = SendEmail()

# basic usage
mail.send('to@example.com', 'subject', 'body')

# use content-type
mail.send('to@example.com', 'subject', '<h1>body</h1>', content_type='html')

# use attachments
mail.send('to@example.com', 'subject', 'body', attachments=['attachment.txt'])

# close the connection
mail.close()

# use with mode
with SendEmail() as mail:
    mail.send('to@example.com', 'subject', 'body')

mailkit.core.SendEmail

class SendEmail(mailkit.core.smtp.config.SmtpConfig)
 |  SendEmail(_case_sensitive: 'bool | None' = None,_env_prefix: 'str | None' = None, _env_file: 'DotenvType | None' = PosixPath('.'), _env_file_encoding: 'str | None' = None, _env_nested_delimiter: 'str | None' = None, _secrets_dir: 'str | Path | None' = None, *, host: str, port: Union[int, NoneType] = None, username: str, password: str, use_ssl: bool = True, use_tls: bool = False, timeout: int = 10) -> None
 |  
 |  send(from_addr: str, to_addrs: Union[str, List[str]], subject: str, body: str = '', content_type: str = 'plain', charset: str = 'utf-8', cc: Union[str, List[str]] = '', bcc: Union[str, List[str]] = '', attachments: Union[str, List[str], NoneType] = None) -> None
 |  
 |  close(self)
 |  
 |  login(self)
 |  
 |  model_dump(self, *, mode: "Literal[('json', 'python')] | str" = 'python', include: 'IncEx' = None, exclude: 'IncEx' = None, by_alias: 'bool' = False, exclude_unset: 'bool' = False, exclude_defaults: 'bool' = False, exclude_none: 'bool' = False, round_trip: 'bool' = False, warnings: 'bool' = True) -> 'dict[str, Any]'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mailkit-1.0.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

mailkit-1.0.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file mailkit-1.0.0.tar.gz.

File metadata

  • Download URL: mailkit-1.0.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.8

File hashes

Hashes for mailkit-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cb7f8f6d347a881d2ae4d84eafbdadd8fc73f553cea0aaded9925f50e238e8c7
MD5 a2b7f6181c2f15da15f83cd28d4f5b74
BLAKE2b-256 005f2c21df51e3cb29730d259eb1fa6e6402696b1b2ba7b0df94fbc675b93a8a

See more details on using hashes here.

File details

Details for the file mailkit-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: mailkit-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.8

File hashes

Hashes for mailkit-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d2a83afd490f56a19afb53fc289c6689e8b3aaf3840bf2384b6025aafea0699
MD5 5a2405cb766ae38740929a2bb1e996bb
BLAKE2b-256 21f69ab2fd46d47bc3369a8f61295748fd11c1640353cab1357d24ce4d578c5a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page