本文整理匯總了Python中django.core.mail.EmailMultiAlternatives方法的典型用法代碼示例。如果您正苦於以下問題:Python mail.EmailMultiAlternatives方法的具體用法?Python mail.EmailMultiAlternatives怎麽用?Python mail.EmailMultiAlternatives使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.core.mail
的用法示例。
在下文中一共展示了mail.EmailMultiAlternatives方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: send_email_ticket_confirm
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 別名]
def send_email_ticket_confirm(request, payment_info):
"""
:param request Django request object
:param payment_info Registration object
"""
mail_title = u"PyCon Korea 2015 등록확인 안내(Registration confirmation)"
product = Product()
variables = Context({
'request': request,
'payment_info': payment_info,
'amount': product.price
})
html = get_template('mail/ticket_registered_html.html').render(variables)
text = get_template('mail/ticket_registered_text.html').render(variables)
msg = EmailMultiAlternatives(
mail_title,
text,
settings.EMAIL_SENDER,
[payment_info.email])
msg.attach_alternative(html, "text/html")
msg.send(fail_silently=False)
示例2: create_digest_email
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 別名]
def create_digest_email(user, digest_frequency, as_of):
"""Return the digest email message for user based on when they last received a digest message."""
start = user_digest_start(user, digest_frequency, as_of)
context = notification_digest(user, start, as_of)
logger.debug('Digest as of %s: %s', start, context)
if context:
context['timestamp'] = as_of
context['site'] = Site.objects.get_current()
context['digest_frequency'] = digest_frequency.name
subject = render_to_string('boards/email/email_digest_subject.txt', context=context)
# remove superfluous line breaks
subject = " ".join(subject.splitlines()).strip()
text_body = render_to_string('boards/email/email_digest_message.txt', context=context)
html_body = render_to_string('boards/email/email_digest_message.html', context=context)
email = EmailMultiAlternatives(subject=subject, body=text_body, to=[user.email])
email.attach_alternative(html_body, "text/html")
return email
else:
return None
示例3: email_user
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 別名]
def email_user(self, text_template, html_template, context):
offering = context['offering']
headers = {
'Precedence': 'bulk',
'Auto-Submitted': 'auto-generated',
'X-coursys-topic': 'discussion',
'X-course': offering.slug,
'Sender': settings.DEFAULT_SENDER_EMAIL,
}
to_email = context['to'].email()
if offering.taemail():
from_email = "%s <%s>" % (offering.name(), offering.taemail())
else:
from_email = settings.DEFAULT_SENDER_EMAIL
text_content = get_template(text_template).render(context)
html_content = get_template(html_template).render(context)
msg = EmailMultiAlternatives(context['subject'], text_content, from_email, [to_email], headers=headers)
msg.attach_alternative(html_content, "text/html")
msg.send()
示例4: email_notify_new_owner
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 別名]
def email_notify_new_owner(self, request, admin):
plaintext = get_template('onlineforms/emails/notify_new_owner.txt')
html = get_template('onlineforms/emails/notify_new_owner.html')
full_url = request.build_absolute_uri(reverse('onlineforms:view_submission',
kwargs={'form_slug': self.form.slug,
'formsubmit_slug': self.slug}))
email_context = {'formsub': self, 'admin': admin, 'adminurl': full_url}
subject = '%s submission transferred' % (self.form.title)
from_email = FormFiller.form_full_email(admin)
to = self.owner.notify_emails()
msg = EmailMultiAlternatives(subject=subject, body=plaintext.render(email_context),
from_email=from_email, to=to, bcc=[admin.full_email()],
headers={'X-coursys-topic': 'onlineforms'})
msg.attach_alternative(html.render(email_context), "text/html")
msg.send()
FormLogEntry.create(form_submission=self, category='MAIL',
description='Notified group "%s" that form submission was transferred to them.'
% (self.owner.name,))
示例5: email_memo
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 別名]
def email_memo(self):
"""
Emails the registration confirmation email if there is one and if none has been emailed for this registration
before.
"""
# If this registration is waitlisted, don't email!
if self.waitlisted:
return
if 'email' not in self.config and self.event.registration_email_text:
subject = 'Registration Confirmation'
from_email = settings.DEFAULT_FROM_EMAIL
content = self.event.registration_email_text
msg = EmailMultiAlternatives(subject, content, from_email,
[self.email], headers={'X-coursys-topic': 'outreach'})
msg.send()
self.email_sent = content
self.save()
示例6: email_contract
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 別名]
def email_contract(self):
unit = self.posting.unit
try:
contract_email = unit.contract_email_text
content = contract_email.content
subject = contract_email.subject
except TAContractEmailText.DoesNotExist:
content = DEFAULT_EMAIL_TEXT
subject = DEFAULT_EMAIL_SUBJECT
response = HttpResponse(content_type="application/pdf")
response['Content-Disposition'] = 'inline; filename="%s-%s.pdf"' % (self.posting.slug,
self.application.person.userid)
ta_form(self, response)
to_email = self.application.person.email()
if self.posting.contact():
from_email = self.posting.contact().email()
else:
from_email = settings.DEFAULT_FROM_EMAIL
msg = EmailMultiAlternatives(subject, content, from_email,
[to_email], headers={'X-coursys-topic': 'ta'})
msg.attach(('"%s-%s.pdf' % (self.posting.slug, self.application.person.userid)), response.getvalue(),
'application/pdf')
msg.send()
示例7: notify_mobile_survey_start
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 別名]
def notify_mobile_survey_start(self, request, mobile_survey):
admin_email = settings.ADMINS[0][1] if settings.ADMINS else ""
email_context = {
"button_text": _("Logon to {app_name}".format(app_name=settings.APP_NAME)),
"link": request.build_absolute_uri(reverse("home")),
"greeting": _(
"Welcome to Arches! You've just been added to a Mobile Survey. \
Please take a moment to review the mobile_survey description and mobile_survey start and end dates."
),
"closing": _(f"If you have any qustions contact the site administrator at {admin_email}."),
}
html_content = render_to_string("email/general_notification.htm", email_context)
text_content = strip_tags(html_content) # this strips the html, so people will have the text as well.
# create the email, and attach the HTML version as well.
for user in self.get_mobile_survey_users(mobile_survey):
msg = EmailMultiAlternatives(
_("You've been invited to an {app_name} Survey!".format(app_name=settings.APP_NAME)),
text_content,
admin_email,
[user.email],
)
msg.attach_alternative(html_content, "text/html")
msg.send()
示例8: send_mail
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 別名]
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()
示例9: send_mail
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 別名]
def send_mail(self, subject_template_name, email_template_name,
context, from_email, to_email, html_email_template_name=None):
"""
Send 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()
示例10: send_complex_mail
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 別名]
def send_complex_mail(subject,
template_txt,
template_html,
_from,
to=None,
cc=None,
bcc=None,
context=None):
context = {} if not context else context
subject, from_email = subject, _from
context['BASE_URL'] = settings.BASE_DOMAIN
text_content = render_to_string(template_txt, Context(context))
html_content = render_to_string(template_html, Context(context))
msg = EmailMultiAlternatives(subject,
text_content,
from_email,
to=to,
cc=cc,
bcc=bcc)
msg.attach_alternative(html_content, "text/html")
msg.send(fail_silently=True)
示例11: send_email
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 別名]
def send_email(to, kind, cc=[], **kwargs):
current_site = Site.objects.get_current()
ctx = {"current_site": current_site, "STATIC_URL": settings.STATIC_URL}
ctx.update(kwargs.get("context", {}))
subject = "[%s] %s" % (
current_site.name,
render_to_string(
"symposion/emails/%s/subject.txt" % kind, ctx
).strip(),
)
message_html = render_to_string(
"symposion/emails/%s/message.html" % kind, ctx
)
message_plaintext = strip_tags(message_html)
from_email = settings.DEFAULT_FROM_EMAIL
email = EmailMultiAlternatives(
subject, message_plaintext, from_email, to, cc=cc
)
email.attach_alternative(message_html, "text/html")
email.send()
示例12: send_mass_html_mail
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 別名]
def send_mass_html_mail(datatuple, fail_silently=False, user=None, password=None,
connection=None):
"""
Given a datatuple of (subject, text_content, html_content, from_email,
recipient_list), sends each message to each recipient list. Returns the
number of emails sent.
If from_email is None, the DEFAULT_FROM_EMAIL setting is used.
If auth_user and auth_password are set, they're used to log in.
If auth_user is None, the EMAIL_HOST_USER setting is used.
If auth_password is None, the EMAIL_HOST_PASSWORD setting is used.
"""
connection = connection or get_connection(
username=user, password=password, fail_silently=fail_silently)
messages = []
default_from = settings.DEFAULT_FROM_EMAIL
for subject, text, html, from_email, recipients in datatuple:
message = EmailMultiAlternatives(
subject, text, default_from, recipients,
headers={'Reply-To': 'Pasporta Servo <saluton@pasportaservo.org>'})
message.attach_alternative(html, 'text/html')
messages.append(message)
return connection.send_messages(messages) or 0
示例13: send_temporary_password
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 別名]
def send_temporary_password(self):
password = User.objects.make_random_password()
self.set_password(password)
subject, from_email, to = (
"OpenCloud Account Credentials",
"support@opencloud.us",
str(self.email),
)
text_content = "This is an important message."
userUrl = "http://%s/" % get_request().get_host()
html_content = (
"""<p>Your account has been created on OpenCloud. Please log in <a href="""
+ userUrl
+ """>here</a> to activate your account<br><br>Username: """
+ self.email
+ """<br>Temporary Password: """
+ password
+ """<br>Please change your password once you successully login into the site.</p>"""
)
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
示例14: send_template
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 別名]
def send_template(email, subject, template_name, context=None, logger=logger):
"""Construct and send an email with subject `subject` to `email`, using the
named email template.
"""
context = context or {}
html, text = render_email_body(template_name, context)
mail = EmailMultiAlternatives(
from_email=f"{settings.EMAIL_NAME} <{settings.EMAIL_ADDRESS}>",
subject=subject,
body=text,
to=(email if isinstance(email, list) else [email]))
mail.attach_alternative(html, "text/html")
mail.send()
logger.info("Sent '%s' email to %s", template_name,
email)
示例15: send_request_email
# 需要導入模塊: from django.core import mail [as 別名]
# 或者: from django.core.mail import EmailMultiAlternatives [as 別名]
def send_request_email(self, form):
subject = '[HKN] Confirm Officer Challenge'
officer_email = form.instance.officer.email
confirm_link = self.request.build_absolute_uri(
reverse("candidate:challengeconfirm", kwargs={ 'pk' : form.instance.id }))
html_content = render_to_string(
'candidate/challenge_request_email.html',
{
'subject': subject,
'candidate_name' : form.instance.requester.get_full_name(),
'candidate_username' : form.instance.requester.username,
'confirm_link' : confirm_link,
'img_link' : get_rand_photo(),
}
)
msg = EmailMultiAlternatives(subject, subject,
'no-reply@hkn.eecs.berkeley.edu', [officer_email])
msg.attach_alternative(html_content, "text/html")
msg.send()