You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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: suqingdong@novogene.com>>> SMTP password: >>> SMTP use ssl [True]: >>> SMTP timeout [10]: login success.Saved configuration to ~/.mailkit.env"# you can also use envernment variablesexport 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: 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 "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
frommailkit.coreimportSendEmail# default auth with ~/.mailkit.envmail=SendEmail()
# basic usagemail.send('to@example.com', 'subject', 'body')
# use content-typemail.send('to@example.com', 'subject', '<h1>body</h1>', content_type='html')
# use attachmentsmail.send('to@example.com', 'subject', 'body', attachments=['attachment.txt'])
# close the connectionmail.close()
# use with modewithSendEmail() asmail:
mail.send('to@example.com', 'subject', 'body')
# auth with another env_filemail=SendEmail(_env_file='.env')
# auth with parametersmail=SendEmail(host='smtp.gmail.com', port=465, username='username@gmail.com', password='password')
# auth wiht environtment variablesimportosos.environ['SMTP_HOST'] ='smtp.gmail.com'os.environ['SMTP_PORT'] =465os.environ['SMTP_USERNAME'] ='username@gmail.com'os.environ['SMTP_PASSWORD'] ='password'os.environ['SMTP_USE_SSL'] =Trueos.environ['SMTP_TIMEOUT'] =10mail=SendEmail()