David,

There may be a package that does it all for you.  But if not, you can
create a model that stores email addresses and send to those
addresses via the Django mail package.  See docs at:
- https://docs.djangoproject.com/en/dev/topics/email/

Here's what my code to send email looks like:

from django.core.mail import EmailMessage, EmailMultiAlternatives
def send(to, subject, body="", cc=[], bcc=[], html_body=None):
    try:
        # Pulls implicitly from settings.py, but can each be overridden here.
        #       EMAIL_HOST
        #       EMAIL_PORT
        #       EMAIL_HOST_USER
        #       EMAIL_HOST_PASSWORD
        #       EMAIL_USE_TLS
        #       DEFAULT_FROM_EMAIL
        if html_body:
            email_message = EmailMultiAlternatives()
        else:
            email_message = EmailMessage()
        email_message.to = to
        email_message.cc = cc
        email_message.bcc = bcc
        email_message.subject = subject
        email_message.body=body
        if html_body:
            email_message.attach_alternative(html_body, "text/html")
        email_message.send(fail_silently=False)
        success = True

    except smtplib.SMTPServerDisconnected as e:
        msg = u'Unable to connect to SMTP server ' + settings.EMAIL_HOST
        msg += u' to send e-mail to ' + unicode(email_message.to)
        exception = e

    except smtplib.SMTPSenderRefused as e:
        msg = u'The SMTP server ' + settings.EMAIL_HOST
        msg += u' refused to send e-mail from ' + unicode(e.sender)
        msg += u' when asked to send e-mail to ' + unicode(email_message.to)
        exception = e

    except smtplib.SMTPRecipientsRefused as e:
        msg = u'The SMTP server ' + settings.EMAIL_HOST
        msg += u' refused to send e-mail to recipients ' + unicode(e.recipients)
        msg += u' when asked to send e-mail to ' + unicode(email_message.to)
        exception = e

    except smtplib.SMTPDataError as e:
        msg = u'The SMTP server ' + settings.EMAIL_HOST
        msg += u' refused to accept the message data'
        msg += u' when asked to send e-mail to ' + unicode(email_message.to)
        exception = e

    except smtplib.SMTPConnectError as e:
        msg = u'Could not establish a connection with the'
        msg += u' SMTP server ' + settings.EMAIL_HOST
        msg += u' to send e-mail to ' + unicode(email_message.to)
        exception = e

    except smtplib.SMTPHeloError as e:
        msg = u'The SMTP server ' + settings.EMAIL_HOST
        msg += u' refused our HELO message'
        msg += u' when sending e-mail to ' + unicode(email_message.to)
        exception = e

    except smtplib.SMTPAuthenticationError as e:
        msg = u'Unable to authenticate with SMTP server ' + settings.EMAIL_HOST
        msg += u' when sending e-mail to ' + unicode(email_message.to)
        exception = e

    except smtplib.SMTPResponseException as e:
        msg = u'The SMTP server ' + settings.EMAIL_HOST
        msg += u' returned: (' + unicode(e.smtp_code) + u') ' + unicode(e.smtp_error)
        msg += u' when sending e-mail to ' + unicode(email_message.to)
        exception = e

    except smtplib.SMTPException as e:
        msg = u'Unable to send e-mail to ' + unicode(email_message.to)
        exception = e

    except BaseException as e:
        msg = u'An unexpected error occurred '
        msg += u' when sending e-mail to ' + unicode(email_message.to)
        msg += u' during step: "' + progress + u'"'
        exception = e

    finally:
        if not success:
            raise EmailException(msg, exception)

--Fred

Fred Stluka -- mailto:f...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.

On 7/18/16 7:02 AM, 'davidt' via Django users wrote:
I have a model that includes an option to subscibe to an email list. However, being somewhat new to Django I am assure how to create a bulk email list form this to send to the appropriate people. I have read various documents on this and have ended up somewhat confused.

Could someone please offer me some enlightenment as to the best way to do this?

Many thanks in advance.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/38f8b1b0-133d-4c32-8c09-a5fc334a9fe2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6cae6cc1-3e7c-c287-fa82-0810a3b3a001%40bristle.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to