Posts

Showing posts from January, 2022

How to send mails with attachment in python?

Image
  smtplib: The smtplib module defines an SMTP client session object that can be used to send emails and files to any Internet machine with an SMTP or ESMTP listener daemon. SMTP needs valid source and destination email ids, and port numbers. The port numbers vary for different sites. For example google, the port is 587. SMTP(Simple Mail Transfer Protocol):   SMTP is used to transfer mail from one user to another user. SMTP is a push protocol and is used to send the mail whereas POP(post office protocol) or IMAP(internet message access protocol) are used to retrieve those emails at the receiver's side. MIME(Multipurpose Internet Mail Extension):  We are using the MIME module to make it more flexible. Using the MIME header we can store the sender and receiver information and some other information. Another most important use of the MIME module is to set the attachment with mail. Some important classes: MIMEBase( _maintype ,  _subtype ,  * ,  policy = compat32 ,  ** _params ): This