django发送和接收电子邮件? [英] django to send AND receive email?

查看:151
本文介绍了django发送和接收电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经很熟悉django的电子邮件发送能力,但是我没有看到任何关于接收和处理用户电子邮件的信息。这个功能是否可用?



几个谷歌搜索没有出现非常有前途的结果。虽然我确实发现这一点:在python中接收和发送电子邮件



我要自己滚吗?如果是这样,我会发布这个应用程序比你说的更快,无论你说什么。



谢谢,
吉姆



更新:我不是要制作一个电子邮件服务器,我只需要添加一些功能,您可以将图像发送到网站并弹出在您的帐户中。

解决方案

有一个名为 jutda-helpdesk ,它使用Python的 poplib imaplib 处理传入的电子邮件。您只需要在POP3或IMAP访问的某个地方使用帐户。



这是从他们的 get_email.py

  def process_mail(mb):
print处理:%s%q
如果mb.email_box_type =='pop3':
如果mb.email_box_ssl:
如果不是mb.email_box_port:mb.email_box_port = 995
server = poplib.POP3_SSL(mb.email_box_host,int(mb.email_box_port))
else:
如果不是mb.email_box_port :mb.email_box_port = 110
server = poplib.POP3(mb.email_box_host,int(mb.email_box_port))
server.getwelcome()
server.user(mb.email_box_user)
server.pass_(mb.email_box_pass)

messageInfo = server.list()[1]

在messagesInfo中的msg:
msgNum = msg.split ()[0]
msgSize = msg.split()[1]
full_message =\\\
.join(server.retr(msgNum)[1])$ ​​b
$ b#

server.dele(msgNum)
server.quit()

elif mb.email_box_type =='imap':
如果mb.email_box_ssl:
如果不是mb.email_box_port:mb.email_box_port = 993
server = imaplib.IMAP4_SSL(mb.email_box_host,int(mb.email_box_port))
else:
如果不是mb。 email_box_port:mb.email_box_port = 143
server = imaplib.IMAP4(mb.email_box_host,int(mb.email_box_port))
server.login(mb.email_box_user,mb.email_box_pass)
服务器。 select(mb.email_box_imap_folder)
status,data = server.search(None,'ALL')
for data [0] .split():
status,data = server。 fetch(num,'(RFC822)')
full_message = data [0] [1]

#消息

server.store(num,'+ FLAGS','\\\Deleted')
server.expunge()
server.close()
server.logout()

mb 只是一些存储所有邮件服务器信息的对象,其余应该很清楚。



您可能需要检查 poplib 和 imaplib 以获取消息的特定部分,但希望这足以让你走。


I have gotten quite familiar with django's email sending abilities, but I havn't seen anything about it receiving and processing emails from users. Is this functionality available?

A few google searches have not turned up very promising results. Though I did find this: Receive and send emails in python

Am I going to have to roll my own? if so, I'll be posting that app faster than you can say... whatever you say.

thanks, Jim

update: I'm not trying to make an email server, I just need to add some functionality where you can email an image to the site and have it pop up in your account.

解决方案

There's an app called jutda-helpdesk that uses Python's poplib and imaplib to process incoming emails. You just have to have an account somewhere with POP3 or IMAP access.

This is adapted from their get_email.py:

def process_mail(mb):
    print "Processing: %s" % q
    if mb.email_box_type == 'pop3':
        if mb.email_box_ssl:
            if not mb.email_box_port: mb.email_box_port = 995
            server = poplib.POP3_SSL(mb.email_box_host, int(mb.email_box_port))
        else:
            if not mb.email_box_port: mb.email_box_port = 110
            server = poplib.POP3(mb.email_box_host, int(mb.email_box_port))
        server.getwelcome()
        server.user(mb.email_box_user)
        server.pass_(mb.email_box_pass)

        messagesInfo = server.list()[1]

        for msg in messagesInfo:
            msgNum = msg.split(" ")[0]
            msgSize = msg.split(" ")[1]
            full_message = "\n".join(server.retr(msgNum)[1])

            # Do something with the message

            server.dele(msgNum)
        server.quit()

    elif mb.email_box_type == 'imap':
        if mb.email_box_ssl:
            if not mb.email_box_port: mb.email_box_port = 993
            server = imaplib.IMAP4_SSL(mb.email_box_host, int(mb.email_box_port))
        else:
            if not mb.email_box_port: mb.email_box_port = 143
            server = imaplib.IMAP4(mb.email_box_host, int(mb.email_box_port))
        server.login(mb.email_box_user, mb.email_box_pass)
        server.select(mb.email_box_imap_folder)
        status, data = server.search(None, 'ALL')
        for num in data[0].split():
            status, data = server.fetch(num, '(RFC822)')
            full_message = data[0][1]

            # Do something with the message

            server.store(num, '+FLAGS', '\\Deleted')
        server.expunge()
        server.close()
        server.logout()

mb is just some object to store all the mail server info, the rest should be pretty clear.

You'll probably need to check the docs on poplib and imaplib to get specific parts of the message, but hopefully this is enough to get you going.

这篇关于django发送和接收电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆