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:
-- 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. |
- Email List 'davidt' via Django users
- Re: Email List Fred Stluka
- Re: Email List Shem Nashon
- Re: Email List 'David Turner' via Django users
- Re: Email List James Schneider