这里有人尝试过localmail lib吗?

时间:2019-11-19 16:10:00

标签: python email

我正在尝试使用localmail库来创建我的电子邮件服务器。我为此创建了一个线程,其中包含SMTP,IMAP和HTTP(现在不相关)的端口。我成功通过SMTP向邮件服务器发送了邮件;现在,我正在尝试使用IMAP来获取数据,尽管可以连接到服务器,但无法选择邮箱并进行搜索。

import imaplib
import smtplib
import email.utils
import threading
import localmail
from email.mime.text import MIMEText
import socket


def local_mail(name):
    print "working with localmail"
    thread = threading.Thread(
        target=localmail.run,
        args=(2025, 2143, 8880, name)
    )
    thread.start()

    print "do_stuff"

    #localmail.shutdown_thread(thread)
    #print "shutdown localmail"


# main

IPAddr = socket.gethostbyname(socket.gethostname())
IpRecv="not publising my ip"
print("Your Computer IP Address is: " + IPAddr)
# Create the message
msg = MIMEText('This is the body of the message.')
msg['To'] = email.utils.formataddr(('Recipient-', IPAddr))
msg['From'] = email.utils.formataddr(('Author-', IpRecv))
msg['Subject'] = 'Simple test message'
local_mail('localmail.mbox')
server = smtplib.SMTP(IPAddr, 2025)
print "opening connection to smtp server"
server.set_debuglevel(True)  # show communication with the server
try:
    server.sendmail(IPAddr, IpRecv, msg.as_string())
    print "sending email..."
except:
    print  "no"
finally:
    server.quit()
import getpass, imaplib

M = imaplib.IMAP4(IPAddr,2143)
M.state="AUTH"
print  "P"
try:
    M.select("inbox")
    print 1
except Exception,e:
    print str(e)
"""
    typ, data = M.search(None, 'ALL')
    for num in data[0].split():
        typ, data = M.fetch(num, '(RFC822)')
        print('Message %s\n%s\n' % (num, data[0][1]))
    M.close()
    M.logout()
except imaplib.IMAP4.error,err:
    print err
    """

我遇到了错误:

  

SELECT命令错误:错误['Unsupported command']

0 个答案:

没有答案