mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-09 22:38:19 +02:00
Minor refactoring, added logic for sending mails to models.py.
This commit is contained in:
parent
41dd2ec645
commit
304bebf147
3 changed files with 24 additions and 6 deletions
|
|
@ -34,7 +34,7 @@ from django_mailbox import utils
|
|||
from django_mailbox.signals import message_received
|
||||
from django_mailbox.transports import Pop3Transport, ImapTransport, \
|
||||
MaildirTransport, MboxTransport, BabylTransport, MHTransport, \
|
||||
MMDFTransport, GmailImapTransport
|
||||
MMDFTransport, GmailImapTransport, SMTPTransport
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -213,6 +213,14 @@ class Mailbox(models.Model):
|
|||
ssl=self.use_ssl
|
||||
)
|
||||
conn.connect(self.username, self.password)
|
||||
elif self.type == 'smtp':
|
||||
conn = SMTPTransport(
|
||||
self.location,
|
||||
port=self.port if self.port else None,
|
||||
ssl=self.use_ssl,
|
||||
tls=self.use_tls
|
||||
)
|
||||
conn.connect(self.username, self.password)
|
||||
elif self.type == 'maildir':
|
||||
conn = MaildirTransport(self.location)
|
||||
elif self.type == 'mbox':
|
||||
|
|
@ -420,6 +428,14 @@ class Mailbox(models.Model):
|
|||
else:
|
||||
self.save()
|
||||
|
||||
def send_mail(self, subject, to, body):
|
||||
connection = self.get_connection()
|
||||
if not connection:
|
||||
return
|
||||
connection.connect(self.username, self.password)
|
||||
connection.send_message(subject, body, self.username, to)
|
||||
return 'Success'
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
|
@ -821,3 +837,4 @@ class MessageAttachment(models.Model):
|
|||
class Meta:
|
||||
verbose_name = _('Message attachment')
|
||||
verbose_name_plural = _('Message attachments')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue