Git Product home page Git Product logo

mailkit's Introduction

Read the Docs (version) PyPI - License PyPI - Python Version PyPI - Version GitHub repo size GitHub top language GitHub last commit (by committer)

A user-friendly Python email toolkit

Installation

python3 -m pip install mailkit

Usage on CMD

Usage: mailkit [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

Usage: mailkit config [OPTIONS]

  initialize the configuration file

Options:
  -s, --show      show the current configuration
  -?, -h, --help  Show this message and exit.


mailkit config
# flowing the instruction to complete the configuration
"
>>> SMTP host: smtp.exmail.qq.com
>>> SMTP port [465]: 
>>> SMTP username: [email protected]
>>> 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 [email protected]
export SMTP_PASSWORD=YOUR_PASSWORD
export SMTP_USE_SSL=True
export SMTP_TIMEOUT=10

mailkit send

Usage: mailkit 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 "[email protected]" -s "subject" -b "body"

# use charset
mailkit send -t "[email protected]" -s "subject" -b "body" -C "gbk"

# use content-type
mailkit send -t "[email protected]" -s "subject" -b "<h1>body</h1>" -C "utf-8" -c "html"

# use cc and bcc
mailkit send -t "[email protected]" -s "subject" -b "body" -cc "[email protected]" -bcc "[email protected]"

# use attachments
mailkit send -t "[email protected]" -s "subject" -b "body" -a "attachment.txt"

# multiple parameters
mailkit send -t "[email protected]" -t "[email protected]" -s "subject" -b "body" -a "attachment.txt" -a "attachment_2.txt"

# auth with parameters
mailkit -H smtp.gmail.com -u [email protected] -p password send -t "[email protected]" -s "subject" -b "body"

# auth with an env_file
mailkit -e .env send -t "[email protected]" -s "subject" -b "body"

Usage in Python

from mailkit.core import SendEmail

# default auth with ~/.mailkit.env
mail = SendEmail() 

# basic usage
mail.send('[email protected]', 'subject', 'body')

# use content-type
mail.send('[email protected]', 'subject', '<h1>body</h1>', content_type='html')

# use attachments
mail.send('[email protected]', 'subject', 'body', attachments=['attachment.txt'])

# close the connection
mail.close()

# use with mode
with SendEmail() as mail:
    mail.send('[email protected]', 'subject', 'body')


# auth with another env_file
mail = SendEmail(_env_file='.env')


# auth with parameters
mail = SendEmail(host='smtp.gmail.com', port=465, username='[email protected]', password='password')


# auth wiht environtment variables
import os
os.environ['SMTP_HOST'] = 'smtp.gmail.com'
os.environ['SMTP_PORT'] = 465
os.environ['SMTP_USERNAME'] = '[email protected]'
os.environ['SMTP_PASSWORD'] = 'password'
os.environ['SMTP_USE_SSL'] = True
os.environ['SMTP_TIMEOUT'] = 10
mail = SendEmail()

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]'

Documents

https://mailkit.readthedocs.io/

mailkit's People

Contributors

suqingdong avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.