def __init__(self, server, username, password):
     POP3.__init__(self, server, 101)
     self.set_debuglevel(2)
     self.user(username)
     response = self.pass_(password)
     if response[:3] != "+OK":
         raise Exception(response)
 def __init__(self, server, username, password):
     "Connect to the POP3 server."
     POP3.__init__(self, server, 110)
     #Uncomment this line to see the details of the POP3 protocol.
     #self.set_debuglevel(2)
     self.user(username)
     response = self.pass_(password)
     if response[:3] != '+OK':
         #There was a problem connecting to the server.
         raise Exception (response)
 def __init__(self, server, username, password):
     "Connect to the POP3 server."
     POP3.__init__(self, server, 110)
     #Uncomment this line to see the details of the POP3 protocol.
     #self.set_debuglevel(2)
     self.user(username)
     response = self.pass_(password)
     if response[:3] != '+OK':
         #There was a problem connecting to the server.
         raise Exception(response)
Exemple #4
0
 def __init__(self, server, username, password):
     "Po³±cz siê z serwerem POP3."
     POP3.__init__(self, server, 110)
     #Usuñ komentarz z poni¿szego wiersza, by zobaczyæ pe³en proces komunikacji.
     #self.set_debuglevel(2)
     self.user(username)
     response = self.pass_(password)
     if response[:3] == '+OK':
         #Wyst±pi³ problem z po³±czeniem.
         raise Exception, response	
Exemple #5
0
def listMails(serv):
    rc = netrc.netrc()
    _, acc, passwd = rc.hosts[serv]
    p = POP(serv)
    p.stls()
    p.user(acc)
    p.pass_(passwd)
    num, _ = p.stat()
    p.quit()
    return num
Exemple #6
0
 def __init__(self,host,port,username,password,tun_type,timeout=5000.0,debug_level=5):
     self.set_debuglevel(debug_level)
     logging.info(FILENAME + ": Connecting %s:%s" % (host,port))
     POP3.__init__(self, host, port, timeout=timeout)
     self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
     self.username = username
     self.password = password
     self.tun_type=tun_type
     self._local = None
     self._remote = None
     self._ipv6 = None
Exemple #7
0
def pop3(host, user, password):
    tests = [POP3(host), POP3_SSL(host)]
    for test in tests:
        test.set_debuglevel(1)
        test.user(user)
        test.pass_(password)
        test.quit()
Exemple #8
0
 def check(self, account):
     ssl = account.get_property("ssl", "false")
     default_port = 995 if ssl else 110
     port = self.get_port_or_default(account, default_port)
     if ssl:
         pop = POP3_SSL(self.get_hostname(account), port)
     else:
         pop = POP3(self.get_hostname(account), port, 7.0)
     try :
         username = self.get_username(account)
         for i in range(0, 3):
             password = self.get_password(account, default_port, i > 0)
             if password == None or password == "":
                 raise Exception(_("Authentication cancelled"))
             try :
                 pop.user(username)
                 pop.pass_(password)            
                 self.save_password(account, password, default_port)            
                 return pop.stat()
             except Exception as e:
                 logger.debug("Error while checking", exc_info = e)
                 try :
                     pop.apop(username, password)            
                     self.save_password(account, password, default_port)            
                     return pop.stat()
                 except Exception as e2:
                     logger.debug("Error while checking", exc_info = e2)
     finally :
         pop.quit()
     return (0, 0)
def receive_mail(host, username, password):
    p = POP3(host)
    p.user(username)
    p.pass_(password)

    mail_id = 0
    print("waiting for mail to appear.", end='')
    while mail_id == 0:
        print(".", end='')
        mail_id = p.stat()[0]
    print(".")  # just for line break
    rsp, msg, siz = p.retr(mail_id)
    p.dele(mail_id)  # mark for deletion
    p.quit()  # log out (also deletes marked mail)

    msg = [x.decode() for x in msg]
    emsg = email.message_from_string('\r\n'.join(msg))
    if emsg.is_multipart():
        for part in emsg.walk():
            print('')
            print(part.get_content_type())
            if part.get_content_type() == 'text/plain':
                print(part.get_payload())
            elif part.get_content_type() == 'text/html':
                print(part.get_payload())
            elif part.get_content_type() == 'image/png':
                print('chapter3_mime_downloaded.png')
                data = part.get_payload(decode=True)  # for when it's binary
                f = open('chapter3_mime_downloaded.png', 'wb')
                data = f.write(data)
                f.close()
 def connect(self):
     if self.source_id and self.source_id.id:
         self.ensure_one()
         if self.source_id.type == 'imap':
             if self.source_id.is_ssl:
                 connection = IMAP4_SSL(self.source_id.server,
                                        int(self.source_id.port))
             else:
                 connection = IMAP4(self.source_id.server,
                                    int(self.source_id.port))
             connection.login(self.user, self.password)
         elif self.type == 'pop':
             if self.source_id.is_ssl:
                 connection = POP3_SSL(self.source_id.server,
                                       int(self.source_id.port))
             else:
                 connection = POP3(self.source_id.server,
                                   int(self.source_id.port))
             # TODO: use this to remove only unread messages
             # connection.user("recent:"+server.user)
             connection.user(self.user)
             connection.pass_(self.password)
         # Add timeout on socket
         connection.sock.settimeout(MAIL_TIMEOUT)
         return connection
     return super(vieterp_fetchmail_server, self).connect()
 def pop3_init(self):
     """与POP3服务器建立连接"""
     try:
         self.pop3_server = POP3(self.pop_server)  #从传入参数获取pop服务器名称
         self.pop3_server.user(self.user)          #从传入参数获取用户名
         self.pop3_server.pass_(self.passwd)       #从传入参数获取密码
     except Exception as e:
         print "POP CONNECT ERROR ->", str(e)
Exemple #12
0
def login_email():
    try:
        pop_conn = POP3(POP3SVR)
        pop_conn.user(USER + '@' + POSTFIX)
        pop_conn.pass_(PSW)
    except error_proto, e:
        print "login failed", e
        return None
def downloadMsg():
    pop = POP3(POPSVR)
    pop.user("wesley")
    pop.pass_("pass")
    rsp, msg, siz = pop.retr(pop.stat()[0])
    # Sting header and compare to orig msg
    seq = msg.index("")
    recvBody = msg[seq + 1:]
Exemple #14
0
 def pop3_init(self):
     """与POP3服务器建立连接"""
     try:
         self.pop3_server = POP3(self.pop_server)
         self.pop3_server.user(self.user)
         self.pop3_server.pass_(self.passwd)
     except Exception as e:
         print "POP CONNECT ERROR ->", str(e)
Exemple #15
0
def connectpop3server():
    pop3server = 'localhost'
    port = '110'
    user = '******'
    password = '******'
    connection = POP3(pop3server, int(port))
    connection.user(user)
    connection.pass_(password)
    return connection
Exemple #16
0
def receive_email(to_receive, receiver_password, server):
    receive_srv = POP3(server)  # 创建一个pop3用于接收对象
    receive_srv.user(to_receive)  # 设置登录服务器的用户名
    receive_srv.pass_(receiver_password)  # 设置登录服务器的密码
    email_list = receive_srv.stat()  # 获取邮件列表
    response, msg, size = receive_srv.retr(email_list[0])  # 下载邮件列表中的第一个邮件
    receive_srv.quit()  # 关闭POP3服务器
    print(response, msg, size, sep='\n-------------------------\n')
    print('POP3 receive the email successfully')
Exemple #17
0
 def __init__(self,
              host,
              port,
              username,
              password,
              tun_type,
              timeout=5000.0,
              debug_level=5):
     self.set_debuglevel(debug_level)
     logging.info(FILENAME + ": Connecting %s:%s" % (host, port))
     POP3.__init__(self, host, port, timeout=timeout)
     self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
     self.username = username
     self.password = password
     self.tun_type = tun_type
     self._local = None
     self._remote = None
     self._ipv6 = None
Exemple #18
0
 def connect(self):
     if self.pop3_ssl:
         self.conn = POP3_SSL(self.pop3_host, int(self.pop3_port))
     else:
         self.conn = POP3(self.pop3_host, int(self.pop3_port))
     #TODO: use this to remove only unread messages
     #conn.user("recent:"+server.user)
     self.conn.user(self.pop3_user)
     self.conn.pass_(self.pop3_pass)
     return self.conn
Exemple #19
0
def pop3(exit):
    try:
        p = POP3(args.hostname)
        p.user(p_file.get('e_user'))
        p.pass_(p_file.get('e_pass'))
        p.quit()
        print(f'OK: POP3 login successful')
        return OK
    except:
        print(f'WARNING: POP3 service was not authorized')
        return CRITICAL
Exemple #20
0
def getMail(config,delmail):

    mailAccount = config['mailAccount']
    mailPassword = config['mailPassword']

    p = POP3('pop.163.com')
    p.user(mailAccount)
    p.pass_(mailPassword)
    resp, mails, octets = p.list()
    index = len(mails)
    resp, lines, octets = p.retr(index)
    if delmail == 1:
        p.dele(index)
    return lines
Exemple #21
0
def pop():
    from poplib import POP3_SSL as POP3
    from settings import *

    s = POP3('pop.gmail.com', 995)
    s.user(un)
    s.pass_(pw)
    rv, msg, sz = s.retr(336)

    print '-' * 25
    for line in msg:
        print line
    print  '-' * 25
    s.quit()
Exemple #22
0
def testMail(config):

    mailAccount = config['mailAccount']
    mailPassword = config['mailPassword']

    try:
        server = smtplib.SMTP('smtp.163.com')
        server.login(mailAccount, mailPassword)
        p = POP3('pop.163.com')
        p.user(mailAccount)
        p.pass_(mailPassword)
        p.list()
    except BaseException:
        return 0
    return 1
Exemple #23
0
def receive_mail(host, username, password):
    p = POP3(host)
    p.user(username)
    p.pass_(password)

    mail_id = 0
    print("waiting for mail to appear.", end='')
    while mail_id == 0:
        print(".", end='')
        mail_id = p.stat()[0]
    print(".")  # just for line break
    rsp, msg, siz = p.retr(mail_id)
    p.dele(mail_id)  # mark for deletion
    p.quit()  # log out (also deletes marked mail)
    for line in msg:
        print(line.decode())
Exemple #24
0
 def __init__(self,
              username: str,
              passwd: str,
              email_host: str = ' pop.163.com') -> None:
     self.server = POP3(email_host)
     self.server.user(username)
     self.server.pass_(passwd)
     resp, self.mails, octets = self.server.list()  # 字节类型
     self.len_string = len(self.mails)  # 从邮件列表中获取最新一封邮件
     if self.len_string > 0:
         resp, self.mail_content, octets = self.server.retr(self.len_string)
         # 'gbk'汉字内码扩展规范
         self.message = Parser().parsestr(
             text=b'\r\n'.join(self.mail_content).decode('gbk'))
     else:
         self.message = ''
Exemple #25
0
def login_pop3(login=None, wait_mail=None):
    if login is None:
        login = config['pop3']['login'][0]
    c = 0
    while True:
        pop3 = POP3(host=config['pop3']['host'])
        pop3.user(login)
        pop3.pass_(config['pop3']['password'])
        if not wait_mail or len(pop3.list()[1]):
            break
        c += 0.5
        pop3.quit()
        time.sleep(0.5)
        if c > wait_mail:
            raise TimeoutError
    return pop3
    def button_confirm_login(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        for server in self.browse(cr, uid, ids, context=context):
            logger.notifyChannel(
                'imap', netsvc.LOG_INFO,
                'fetchmail start checking for new emails on %s' %
                (server.name))
            context.update({
                'server_id': server.id,
                'server_type': server.type
            })
            try:
                if server.type == 'imap':
                    imap_server = None
                    if server.is_ssl:
                        imap_server = IMAP4_SSL(server.server,
                                                int(server.port))
                    else:
                        imap_server = IMAP4(server.server, int(server.port))

                    imap_server.login(server.user, server.password)
                    ret_server = imap_server

                elif server.type == 'pop':
                    pop_server = None
                    logger.notifyChannel('imap', netsvc.LOG_INFO,
                                         'pop %s' % (int(server.port)))
                    if server.is_ssl:
                        pop_server = POP3_SSL(server.server, int(server.port))
                    else:
                        pop_server = POP3(server.server, int(server.port))
                    #TODO: use this to remove only unread messages
                    #pop_server.user("recent:"+server.user)
                    pop_server.user(server.user)
                    pop_server.pass_(server.password)
                    ret_server = pop_server

                self.write(cr, uid, [server.id], {'state': 'done'})
                if context.get('get_server', False):
                    return ret_server
            except Exception, e:
                logger.notifyChannel(server.type, netsvc.LOG_WARNING,
                                     '%s' % (e))
Exemple #27
0
 def connect(self, cr, uid, server_id, context=None):
     if isinstance(server_id, (list, tuple)):
         server_id = server_id[0]
     server = self.browse(cr, uid, server_id, context)
     if server.type == 'imap':
         if server.is_ssl:
             connection = IMAP4_SSL(server.server, int(server.port))
         else:
             connection = IMAP4(server.server, int(server.port))
         connection.login(server.user, server.password)
     elif server.type == 'pop':
         if server.is_ssl:
             connection = POP3_SSL(server.server, int(server.port))
         else:
             connection = POP3(server.server, int(server.port))
         #TODO: use this to remove only unread messages
         #connection.user("recent:"+server.user)
         connection.user(server.user)
         connection.pass_(server.password)
     return connection
Exemple #28
0
 def connect(self):
     self.ensure_one()
     if self.server_type == 'imap':
         if self.is_ssl:
             connection = IMAP4_SSL(self.server, int(self.port))
         else:
             connection = IMAP4(self.server, int(self.port))
         self._imap_login(connection)
     elif self.server_type == 'pop':
         if self.is_ssl:
             connection = POP3_SSL(self.server, int(self.port))
         else:
             connection = POP3(self.server, int(self.port))
         #TODO: use this to remove only unread messages
         #connection.user("recent:"+server.user)
         connection.user(self.user)
         connection.pass_(self.password)
     # Add timeout on socket
     connection.sock.settimeout(MAIL_TIMEOUT)
     return connection
Exemple #29
0
def auto_send_mail(msg, content, sender_emailaddr, sender_username,
                   sender_password, receiver_emailaddr, receiver_username,
                   receiver_password):

    smtp_server = 'smtp.163.com'
    pop3_server = 'pop.163.com'

    mail_headers = ('From: %s' % sender_emailaddr,
                    'To: %s' % receiver_emailaddr, 'Subject: %s' % msg)
    mail_body = "%s" % content
    # 开头 + 邮件内容
    mail_msg = '/r/n/r/n'.join(
        ['/r/n'.join(mail_headers), '/r/n'.join(mail_body)])

    send_server = SMTP(smtp_server)
    # sendSer.set_debuglevel(1)
    # print sendSer.ehlo()[0]  # 服务器属性等
    send_server.login(sender_username, sender_password)  # 登录
    try:
        # 第二个参数接受一个列表
        errs = send_server.sendmail(sender_emailaddr, receiver_emailaddr,
                                    mail_msg)
    except SMTPRecipientsRefused:
        print('server refused....')
        sys.exit(1)
    send_server.quit()

    # 开始接收邮件
    receiver_server = POP3(pop3_server)
    receiver_server.user(receiver_username)
    receiver_server.pass_(receiver_password)

    rsp, msg, siz = receiver_server.retr(receiver_server.stat()[0])
    # sep = msg.index('')
    if msg:
        for i in msg:
            print(i)
    # revcBody = msg[sep + 1:]
    # assert origBody == revcBody
    print('successful get ....')
Exemple #30
0
 def connect(self):
     """
         Fonction de connexion au serveur de mail
     """
     if self.type == 'imap':
         if self.is_ssl:
             connection = IMAP4_SSL(self.server, int(self.port))
         else:
             connection = IMAP4(self.server, int(self.port))
         connection.login(self.user, self.password)
     elif self.type == 'pop':
         if self.is_ssl:
             connection = POP3_SSL(self.server, int(self.port))
         else:
             connection = POP3(self.server, int(self.port))
         #TODO: use this to remove only unread messages
         #connection.user("recent:"+server.user)
         connection.user(self.user)
         connection.pass_(self.password)
     # Add timeout on socket
     connection.sock.settimeout(MAIL_TIMEOUT)
     return connection
def get_credit_card_bill_by_pop3(email_account, email_password):
    email_suffix = get_email_suffix(email_account)
    pop3_server_addr = POP3_SUFFIX_ADDRESS_DICT.get(email_suffix, "pop." + email_suffix)

    pop3_server = POP3(pop3_server_addr)
    try:
        try:
            pop3_server.user(email_account)
            pop3_server.pass_(email_password)
        except error_proto:
            raise

        yield True

        email_count, _ = pop3_server.stat()
        # _, mails, _ = pop3_server.list()
        for index in range(1, email_count + 1):
            try:
                _, email_lines, _ = pop3_server.retr(index)  # 索引号从1开始的
                email_content_str = '\r\n'.join(list(map(bytes.decode, email_lines)))
                msg = Parser().parsestr(email_content_str)
            except Exception:
                print_exc()
                continue

            address, subject = parse_email_headers(msg)
            bank_name = check_email_credit_card_by_address(subject, address)
            if bank_name:
                try:
                    content = parse_email(msg)
                except Exception:
                    print_exc()
                    content = '解析邮件正文出错'

                yield (bank_name, subject, content)
    finally:
        pop3_server.quit()
Exemple #32
0
from smtplib import SMTP
from poplib import POP3
from time import sleep

SMTPSVR = 'smtp.python.is.cool'
POP3SVR = 'pop.python.is.cool'

who = '*****@*****.**'
body = '''\
From: %(who)s
To: %(who)s
Subject: test msg

Hello World!
''' % {'who': who}

sendSvr = SMTP(SMTPSVR)
errs = sendSvr.sendmail(who, [who], origMsg)
sendSvr.quit()
assert len(errs) == 0, errs
sleep(10)

recvSvr = POP3(POP3SVR)
recvSvr.user('wesley')
recvSvr.pass_('youllNeverGuess')
rsp, msg, siz = recvSvr.retr(recvSvr.star()[0])
# strip headers and compare to orig msg
sep = msg.index('')
recBody = msg[sep+1:]
assert origBody == recvBody 
    def index_windows(self):
        """主界面"""
        self.index_window = Tk()
        self.index_window.title("index windows")
        self.index_window.resizable(width=False, height=False)
        self.index_window.geometry('900x700')

        # 当前用户信息
        Label(self.index_window, text="User: "******"宋体,15", selectmode=BROWSE)
        self.msg_list.place(x=0, y=30)
        self.msg_list.bind(sequence="<Double-Button-1>", func=self.open_email)

        # 登陆POP服务器 POP.XXX.XXX
        try:
            self.pop3_server = POP3(self.pop_server)
            self.pop3_server.user(self.user)
            self.pop3_server.pass_(self.passwd)
        except Exception as e:
            print "POP CONNECT ERROR ->", str(e)

        rep, self.msg, size = self.pop3_server.list()  # self.msg为全部收信

        all_recv_email = []
        email_num = len(self.msg)
        self.stmp_num = email_num
        while email_num > 0:
            try:
                rep, text, size = self.pop3_server.retr(email_num)
                msg_content = b'\r\n'.join(text).decode().encode('utf-8')
                msg = Parser().parsestr(msg_content)
                list = Recv_email().info_digest(msg)
                list.insert(0, str(self.stmp_num - email_num + 1) + " : ")
                all_recv_email.append(list)
            except Exception as e:
                print "POP PARSER ERROR ->", str(e)
                pass
            email_num -= 1

        for item in all_recv_email:
            if len(self.black_lists) != 0:
                if str(item[1]).find(self.black_lists[0]) != -1:
                    print self.black_lists[0]
                    print "THIS EMAIL IN BLACK LIST"
                    self.black_num += 1
                    pass
                else:
                    print str(item[1])
                    Id = str(item[0])
                    From = 'From: ' + str(item[1])
                    To = 'To: ' + str(item[2])
                    Subject = 'Subject: ' + item[3]
                    parma = Id + From + To + Subject
                    self.msg_list.insert(END, parma)
            else:
                self.black_num = 0
                Id = str(item[0])
                From = 'From: ' + str(item[1])
                To = 'To: ' + str(item[2])
                print 'hh'
                Subject = 'Subject: ' + item[3]

                parma = Id + From + To + Subject
                self.msg_list.insert(END, parma)
            # print parma
        scroll_bar.config(command=self.msg_list.yview)

        # 提示信息
        Label(self.index_window, text="收件箱: " + str(len(self.msg) - self.black_num) + "封", bg="#e6ebe0",
              font="黑体, 15").place(x=0, y=0)

        # 收件箱按钮
        # Button(self.index_window, text="已发送", command=self.delete_msg, width=8). place(x=200, y=0)

        # 删除按钮
        Button(self.index_window, text="删除", command=self.delete_msg, width=8). place(x=0, y=580)

        # 刷新按钮
        Button(self.index_window, text="刷新", command=self.FreshIndex_windows, width=8). place(x=90, y=580)

        # 读取按钮
        # Button(self.index_window, text="打开", command=self.delete_msg, width=8). place(x=180, y=580)

        # 写信按钮
        Button(self.index_window, text="写信", command=self.send_windows, width=8). place(x=680, y=580)

        # 退出按钮
        Button(self.index_window, text="退出", command=self.sys_quit, width=8). place(x=780, y=580)

        # 邮箱信息验证?
        # 待添加

        # 伪造邮件地址黑名单
        Button(self.index_window, text="设置黑名单", command=self.black_list_windows, width=8). place(x=780, y=620)

        # 删除其他窗口
        try:
            self.EMail_UI.destroy()  # 清除初始化窗口
            self.check.destroy()  # 清除提示窗口
        except:
            pass

        # 循环
        self.index_window.mainloop()
Exemple #34
0
#!/usr/bin/python3.7
from poplib import POP3

username = '******'
password = '******'

pop3conn = POP3('10.171.1.129', '110')
pop3conn.user(username)
pop3conn.pass_(password)

pop3srvmsg = pop3conn.getwelcome().decode('utf-8')

print('Connection successful')
print(pop3srvmsg)
print(pop3conn.stat())

pop3conn.quit()