diff --git a/django_mailbox/models.py b/django_mailbox/models.py index f4b5dc6..4e3fef4 100644 --- a/django_mailbox/models.py +++ b/django_mailbox/models.py @@ -15,7 +15,7 @@ from django.core.files.base import ContentFile from django.db import models from django_mailbox.transports import Pop3Transport, ImapTransport,\ MaildirTransport, MboxTransport, BabylTransport, MHTransport, \ - MMDFTransport + MMDFTransport, GmailImapTransport from django_mailbox.signals import message_received import six from six.moves.urllib.parse import parse_qs, unquote, urlparse @@ -168,6 +168,14 @@ class Mailbox(models.Model): archive=self.archive ) conn.connect(self.username, self.password) + elif self.type == 'gmail': + conn = GmailImapTransport( + self.location, + port=self.port if self.port else None, + ssl=True, + archive=self.archive + ) + conn.connect(self.username, self.password) elif self.type == 'pop3': conn = Pop3Transport( self.location, diff --git a/docs/topics/mailbox_types.rst b/docs/topics/mailbox_types.rst index 014960d..eb01ad0 100644 --- a/docs/topics/mailbox_types.rst +++ b/docs/topics/mailbox_types.rst @@ -61,6 +61,20 @@ would enter the following as your URI:: imap+ssl://youremailaddress%40gmail.com:1234@imap.gmail.com?archive=Archived +Gmail IMAP with Oauth2 authentication +------------------------------------- + +Gmail supports using oauth2 for authentication_ which is more secure. +To handle the handshake and storing the credentials, use python-social-auth_. + +.. _authentication: https://developers.google.com/gmail/xoauth2_protocol +.. _python-social-auth: http://psa.matiasaguirre.net/ + +The Gmail Mailbox is also a regular IMAP mailbox, but the password will be ignored if oauth2 succeeds. It can fall back to password as needed. +Build your URI accordingly:: + + gmail+ssl://youremailaddress%40gmail.com:oauth2@imap.gmail.com?archive=Archived + Local File-based Mailboxes --------------------------