POP and Imap-post Office Protocol and Internet Message Access Protocol

Source: Internet
Author: User
Tags imap

1POP andImap-post Office Protocol andInternet Message Access Protocol2 3 the protocol used to download messages from the SMTP Server.4 5POP-The Post Office Protocol6 by Poplib linked servers,7 example,8             ImportSYS9             Importpoplib, emailTenHost ="' OneUserID ='userid' APW ='PW' -Storedir ="' #Email Stored directory (the mailbox) -P =Poplib. POP3 (host) the             Try: - p.user (userid) - P.pass_ (PW) -             exceptPoplib.error_proto as E: +                 Print("Login failed:", E) - sys.exit () +  AMaillist = P.list () [1]#The list of message in the mailbox at             Print("%d mails."%Len (maillist)) -Dellist = [] -  -              forIteminchMaillist:#Email Download -Number, octets = Item.split (' ') -                 Print("Start downloading mail%s (%s Bytes)"%(number, octets)) inLines = P.RETR (number) [1]#retrieve the ' number ' th email -msg = Email.message_from_string ("\ n". Join (lines))#Email Object to With Open (Storedir) as FH: +Fh.write (msg.as_string (unixfrom=1) +"\ n") - dellist.append (number) the                 Print("downloaded mail%s (%s Bytes)"%(number, octets)) *  $Counter =0Panax Notoginseng              forNuminchDellist:#Delete Email -Counter + = 1 the                 Print("Deleting Mail%d of%d"%(counter, Len (dellist))) +P.dele (number)#Delete Mail A  the             Print("%d emails were deleted from server"%counter) +P.quit ()#Logout from server -  $IMAP-Internet Message Access Protocol $ IMAP is more sophisticated and more powerful than POP protocol -Example, opens a mailbox andRetrieves andPrints all messages: -  the             ImportGetpass, Imaplib -M =Imaplib. IMAP4 ()Wuyi M.login (Getpass.getuser (), Getpass.getpass ()) the M.select () -Typ, data = M.search (None,' All') Wu              forNuminchdata[0].split (): -Typ, data = M.fetch (num,'(RFC822)') About                 Print('Message%s\n%s\n'% (num, data[0][1])) $ m.close () - m.logout () -  - Reference, A python doc, +Https://docs.python.org/3/library/imaplib.html

POP and Imap-post Office Protocol and Internet Message Access Protocol

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.