How Python receives new Gmail messages and sends them to Gtalk

Source: Internet
Author: User
This example describes how Python receives new Gmail messages and sends them to gtalk. Share to everyone for your reference. The implementation method is as follows:

#!/usr/bin/env python#-*-coding:utf-8-*-import imaplibimport string, Randomimport Stringio, Rfc822import emailfrom goo GLE.APPENGINE.API Import xmppSERVER1 = "imap.gmail.com" USER = "Yeah" PASSWORD = "Ohmyga" # Connect to Serverserver = Imaplib (SERVER1, 993) # Loginserver.login (USER, PASSWORD) server.select () # list items on serverstatus, data = Server.search (None, "(unseen)") mails = Data[0].split () if data[0]! = ": print" has mails "user_address = ' wangnaide@gmail.com ' for Num in D Ata[0].split (): TPE, raw_msg = Server.fetch (num, ' (RFC822) ') msg = email.message_from_string (raw_msg[0][1]) #Subj ECTs sbj, Ecode = email. Header.decode_header (msg[' subject ']) [0] #from, sender frm = "for FTS, ecode in email. Header.decode_header (msg[' from '): frm = frm + fts if Xmpp.get_presence (user_address): xmpp.send_message (user _address, frm + ': ' + sbj) server.store (num, ' +flags ', ' \\SEEN ') #print frm + ":" + sbjserver.close () server.logout ()

Hopefully this article will help you with Python programming.

  • 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.