这里有人尝试过本地邮件库吗?

2024-10-01 17:30:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用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 command error: BAD ['Unsupported command']


Tags: theimportdataserveremailmsgutilssocket

热门问题