Here are the examples of the python api django.core.mail.EmailMultiAlternatives taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
102 Examples
3
View Complete Implementation : forms.py
Copyright MIT License
Author : bpgc-cte
Copyright MIT License
Author : bpgc-cte
def send_mail(self, subject_template_name, email_template_name,
context, from_email, to_email, html_email_template_name=None):
"""
Sends a django.core.mail.EmailMultiAlternatives to `to_email`.
"""
subject = loader.render_to_string(subject_template_name, context)
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
body = loader.render_to_string(email_template_name, context)
email_message = EmailMultiAlternatives(subject, body, from_email, [to_email])
if html_email_template_name is not None:
html_email = loader.render_to_string(html_email_template_name, context)
email_message.attach_alternative(html_email, 'text/html')
email_message.send()
3
View Complete Implementation : utils.py
Copyright MIT License
Author : coogger
Copyright MIT License
Author : coogger
def send_mail(subject, template_name, context, to):
html_content = render_to_string(template_name, context)
text_content = strip_tags(html_content)
for to in [user.email for user in to if user.userprofile.email_permission]:
msg = EmailMultiAlternatives(
subject, text_content, settings.EMAIL_HOST_USER, [to]
)
msg.attach_alternative(html_content, "text/html")
msg.send()
3
View Complete Implementation : integration_test.py
Copyright MIT License
Author : datosgobar
Copyright MIT License
Author : datosgobar
def send_email(result: list, task: IntegrationTestTask):
subject = u'[{}] API Series de Tiempo: Test de integración'.format(settings.ENV_TYPE)
emails = IntegrationTestConfig.get_solo().recipients.values_list('email', flat=True)
if not emails:
task.log("No hay usuarios registrados para recibir los reportes del test. Mail no enviado.")
return
msg = "Errores en los datos de las series detectados. Ver el archivo adjunto"
config = DynamicEmailConfiguration.get_solo()
mail = EmailMultiAlternatives(subject, msg, from_email=config.from_email, to=emails)
mail.attach('errors.csv', generate_errors_csv(result), 'text/csv')
sent = mail.send()
if not sent:
task.log("Error mandando el reporte")
3
View Complete Implementation : email.py
Copyright MIT License
Author : diegojromerolopez
Copyright MIT License
Author : diegojromerolopez
def warn_administrators(subject, message):
email_subject = u"[Djanban] [Warning] {0}".format(subject)
report_recipients = ReportRecipient.objects.filter(is_active=True, send_errors=True)
for report_recipient in report_recipients:
email_message = EmailMultiAlternatives(email_subject, message, settings.EMAIL_HOST_USER,
[report_recipient.email])
email_message.send()
3
View Complete Implementation : utils.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : egorsmkv
Copyright BSD 3-Clause "New" or "Revised" License
Author : egorsmkv
def send_mail(to, template, context):
html_content = render_to_string(f'accounts/emails/{template}.html', context)
text_content = render_to_string(f'accounts/emails/{template}.txt', context)
msg = EmailMultiAlternatives(context['subject'], text_content, settings.DEFAULT_FROM_EMAIL, [to])
msg.attach_alternative(html_content, 'text/html')
msg.send()
3
View Complete Implementation : payment_email.py
Copyright GNU General Public License v3.0
Author : evernote
Copyright GNU General Public License v3.0
Author : evernote
def send(self):
"""Sends the payment email along with the invoice."""
body = self.get_body()
# Set non-empty body according to
# http://stackoverflow.com/questions/14580176/confusion-with-sending-email-in-django
mail = EmailMultiAlternatives(subject=self.get_subject(),
body=strip_tags(body),
to=self.get_recipient_list(),
cc=self.get_cc_list(),
bcc=self.get_bcc_list())
mail.attach_alternative(body, 'text/html')
for attachment in self.attachments:
mail.attach_file(attachment[0], attachment[1])
return mail.send()
3
View Complete Implementation : htmlmail.py
Copyright BSD 2-Clause "Simplified" License
Author : evrenesat
Copyright BSD 2-Clause "Simplified" License
Author : evrenesat
def send_html_mail(subject, recipient, message, template='',
recipient_name='', sender_name='', sender=None,
CHARSET=CHARSET):
html = render(message, template)
msg = EmailMultiAlternatives(
subject=subject,
body=html,
to=[named(recipient, recipient_name)],
from_email=named(sender, sender_name),
)
msg.content_subtype = "html"
msg.send()
3
View Complete Implementation : email.py
Copyright MIT License
Author : F0RE1GNERS
Copyright MIT License
Author : F0RE1GNERS
def send_mail_with_bcc(subject, html_message, recipient_list, fail_silently=False):
def divide_group(lst, k):
return [lst[i:i + k] for i in range(0, len(lst), k)]
for grp in divide_group(recipient_list, 100):
try:
connection = get_connection(
username=None,
pastword=None,
fail_silently=fail_silently,
)
mail = EmailMultiAlternatives(subject, bcc=grp, connection=connection)
mail.attach_alternative(html_message, 'text/html')
mail.send()
except:
traceback.print_exc()
time.sleep(30)
3
View Complete Implementation : views.py
Copyright GNU General Public License v2.0
Author : geekwolf
Copyright GNU General Public License v2.0
Author : geekwolf
def exec_send(content_id, email_list):
data = collections.defaultdict(dict)
from_email = settings.DEFAULT_FROM_EMAIL
text_content = '这是一封重要的邮件.'
content = Content.objects.select_related().get(id=content_id)
data['content'] = content
data['domain'] = settings.EMAIL_DOMAIN_LINK
subject = '【故障报告】' + str(content.satle)
time_count(content, content.start_time, content.end_time)
msg_html = render_to_string('mail/detail_template.html', data)
# send_mail('Subject here', 'Here is the message.', settings.DEFAULT_FROM_EMAIL,email_list, fail_silently=False)
msg = EmailMultiAlternatives(subject, text_content, from_email, email_list)
msg.attach_alternative(msg_html, "text/html")
msg.send()
3
View Complete Implementation : notify.py
Copyright MIT License
Author : ilavender
Copyright MIT License
Author : ilavender
def register_email(message):
register_email_plaintext = get_template('registration/email_register.txt')
register_email_htmly = get_template('registration/email_register.html')
send_to = message['register_user_email']
username = message['register_user_name']
registration_link = message['registration_link']
subject, from_email, to = message['subject'], message['from_email'], message['to_email']
text_content = register_email_plaintext.render({ 'username': username, 'registration_link': registration_link })
html_content = register_email_htmly.render(d)
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()