Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django to send AND receive email?

Tags:

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.

like image 380
Jiaaro Avatar asked Apr 08 '09 15:04

Jiaaro


People also ask

What is email host in Django?

Mail is sent using the SMTP host and port specified in the EMAIL_HOST and EMAIL_PORT settings. The EMAIL_HOST_USER and EMAIL_HOST_PASSWORD settings, if set, are used to authenticate to the SMTP server, and the EMAIL_USE_TLS and EMAIL_USE_SSL settings control whether a secure connection is used.

How do I send multiple emails in Django?

How to send multiple mass emails django. We need to create a Tuple of messages and send them using send mass mail. In this tutorial, we create a project which sends email using Django. We fill the data in the form and send it using Django Email.

How do I send an email using python?

Set up a secure connection using SMTP_SSL() and . starttls() Use Python's built-in smtplib library to send basic emails. Send emails with HTML content and attachments using the email package.


2 Answers

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.

like image 119
tghw Avatar answered Sep 18 '22 05:09

tghw


I know this question is pretty old now but just thought I'd add for future reference that you might want to give http://cloudmailin.com a go. We have quite a few django users using the system and it should be a little simpler than the proposed solution.

like image 45
Steve Smith Avatar answered Sep 21 '22 05:09

Steve Smith