Package: mailkit
A user-friendly Python email toolkitInstallationpython3-mpipinstallmailkitUsage on CMDUsage:python-mmailkit.bin.main[OPTIONS]COMMAND[ARGS]...Auser-friendlyPythonemailtoolkit

Options:--versionShowtheversionandexit.-H,--hostTEXTSMTPserverhostnameorIPaddress-P,--portINTEGERSMTPserverport-u,--usernameTEXTSMTPserverusername-p,--passwordTEXTSMTPserverpassword-s,--use-sslBOOLEANUseSSLconnection[default:True]-t,--timeoutINTEGERSMTPservertimeout[default:10]-e,--env-fileTEXTTheenvironmentfiletoload[default:~/.mailkit.env]-h,-?,--helpShowthismessageandexit.

Commands:configinitializetheconfigurationfilesendsendemailtouser(s)mailkit configUsage:python-mmailkit.bin.mainconfig[OPTIONS]initializetheconfigurationfile

Options:-s,--showshowthecurrentconfiguration-?,-h,--helpShowthismessageandexit.


mailkitconfig# 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 variablesexportSMTP_HOST=smtp.gmail.comexportSMTP_PORT=465exportSMTP_USERNAME=suqingdong@gmail.comexportSMTP_PASSWORD=YOUR_PASSWORDexportSMTP_USE_SSL=TrueexportSMTP_TIMEOUT=10mailkit sendUsage:python-mmailkit.bin.mainsend[OPTIONS]sendemailtouser(s)Options:-f,--from-addrTEXTthedisplayaddressofthesender,defaultistheloginusername-t,--to-addrsTEXTtherecipientaddress(es)[required]-s,--subjectTEXTthesubjectoftheemail[required]-b,--bodyTEXTthebodyoftheemail-a,--attachmentsTEXTtheattachmentsoftheemail-C,--charsetTEXTthecharsetoftheemail[default:utf-8]-c,--content-typeTEXTthecontenttypeoftheemail,eg.:plain,html[default:plain]-cc,--ccTEXTtheccaddress(es)-bcc,--bccTEXTthebccaddress(es)-h,-?,--helpShowthismessageandexit.# Examples:# basic usagemailkitsend-t"to@example.com"-s"subject"-b"body"# use charsetmailkitsend-t"to@example.com"-s"subject"-b"body"-C"gbk"# use content-typemailkitsend-t"to@example.com"-s"subject"-b"<h1>body</h1>"-C"utf-8"-c"html"# use cc and bccmailkitsend-t"to@example.com"-s"subject"-b"body"-cc"cc@example.com"-bcc"bcc@example.com"# use attachmentsmailkitsend-t"to@example.com"-s"subject"-b"body"-a"attachment.txt"# multiple parametersmailkitsend-t"to_1@example.com"-t"to_2@example.com"-s"subject"-b"body"-a"attachment.txt"-a"attachment_2.txt"# auth with parametersmailkit-Hsmtp.gmail.com-uusername@gmail.com-ppasswordsend-t"to@example.com"-s"subject"-b"body"# auth with an env_filemailkit-e.envsend-t"to@example.com"-s"subject"-b"body"Usage in Pythonfrommailkit.coreimportSendEmailmail=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 env_filemail=SendEmail(_env_file='.env')# 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()mailkit.core.SendEmailclassSendEmail(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]'Documentshttps://mailkit.readthedocs.io/