本文整理汇总了Python中tendenci.apps.emails.models.Email.recipient方法的典型用法代码示例。如果您正苦于以下问题:Python Email.recipient方法的具体用法?Python Email.recipient怎么用?Python Email.recipient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tendenci.apps.emails.models.Email
的用法示例。
在下文中一共展示了Email.recipient方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: message
# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import recipient [as 别名]
def message(request, group_slug, template_name="user_groups/message.html"):
"""
Send a message to the group
"""
from tendenci.apps.emails.models import Email
group = get_object_or_404(Group, slug=group_slug)
EventLog.objects.log(instance=group)
members = GroupMembership.objects.filter(group=group, status=True, status_detail="active")
num_members = members.count()
form = MessageForm(request.POST or None, request=request, num_members=num_members)
if request.method == "POST" and form.is_valid():
email = Email()
email.sender_display = request.user.get_full_name()
email.sender = get_setting("site", "global", "siteemailnoreplyaddress")
email.reply_to = email.sender
email.content_type = email.CONTENT_TYPE_HTML
email.subject = form.cleaned_data["subject"]
email.body = form.cleaned_data["body"]
email.save(request.user)
# send email to myself (testing email)
if form.cleaned_data["is_test"]:
email.recipient = request.user.email
email.send()
messages.add_message(request, messages.SUCCESS, _("Successfully sent test email to yourself"))
EventLog.objects.log(instance=email)
else:
# send email to members
for member in members:
email.recipient = member.member.email
email.send()
messages.add_message(
request,
messages.SUCCESS,
_("Successfully sent email to all %(num)s members in this group" % {"num": num_members}),
)
EventLog.objects.log(instance=email)
return redirect("group.detail", group_slug=group_slug)
else:
print "form errors", form.errors.items()
return render(request, template_name, {"group": group, "num_members": num_members, "form": form})
示例2: send_organizer_confirmation
# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import recipient [as 别名]
def send_organizer_confirmation(self, event):
from tendenci.apps.emails.models import Email
from tendenci.apps.site_settings.utils import get_setting
email = Email()
if event.organizer and event.organizer.user \
and event.organizer.user.email:
email.recipient = event.organizer.user.email
else:
email.recipient = get_setting('module', 'events', 'admin_emails')
if not email.recipient:
email.recipient = get_setting('site', 'global',
'sitecontactemail')
email.subject = '%s Event Reminders Distributed for: %s' % (
get_setting('site', 'global',
'sitedisplayname'),
event.title
)
email.body = self.get_reminder_conf_body(event)
email.send()
示例3: email_script_errors
# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import recipient [as 别名]
def email_script_errors(err_msg):
"""Send error message to us in case of an error.
"""
email = Email()
email.sender = get_setting('site', 'global', 'siteemailnoreplyaddress')
email.sender_display = get_setting('site', 'global', 'sitedisplayname')
site_url = get_setting('site', 'global', 'siteurl')
now = datetime.now()
nowstr = time.strftime("%d-%b-%y %I:%M %p", now.timetuple())
email.recipient = get_script_support_emails()
if email.recipient:
email.body = '%s \n\nTime Submitted: %s\n' % (err_msg, nowstr)
email.content_type = "text"
email.subject = 'Error Setting Up Campaign Monitor Account on New Site %s' % site_url
email.send()
示例4: email_invoice
# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import recipient [as 别名]
def email_invoice(request, invoice_id, form_class=EmailInvoiceForm,
template_name='invoices/email_invoice.html'):
if not request.user.profile.is_superuser:
raise Http403
invoice = get_object_or_404(Invoice, pk=invoice_id)
if request.method == "POST":
email = Email()
form = form_class(request.POST, instance=email)
if form.is_valid():
email = form.save(commit=False)
email.sender_display = request.user.get_full_name()
email.reply_to = request.user.email
email.recipient = form.cleaned_data['recipient']
email.content_type = "html"
email.recipient_cc = form.cleaned_data['cc']
attachment = form.cleaned_data['attachment']
kwargs = {}
if attachment:
result = invoice_pdf(request, invoice)
kwargs['attachments'] = [("invoice_{}.pdf".format(invoice.id),
result.getvalue(),
'application/pdf')]
email.send(**kwargs)
EventLog.objects.log(instance=email)
msg_string = 'Successfully sent email invoice to {}.'.format(email.recipient)
messages.add_message(request, messages.SUCCESS, msg_string)
return HttpResponseRedirect(reverse('invoice.view', args=([invoice_id])))
else:
template = get_template("invoices/email_invoice_template.html")
body_initial = template.render(RequestContext(request, {
'invoice': invoice,}))
form = form_class(initial={'subject': 'Invoice for {}'.format(invoice.title),
'recipient': invoice.bill_to_email,
'body': body_initial})
return render_to_response(template_name, {
'invoice': invoice,
'form': form
},context_instance=RequestContext(request))
示例5: form_detail
# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import recipient [as 别名]
def form_detail(request, slug, template="forms/form_detail.html"):
"""
Display a built form and handle submission.
"""
published = Form.objects.published(for_user=request.user)
form = get_object_or_404(published, slug=slug)
if not has_view_perm(request.user,'forms.view_form',form):
raise Http403
# If form has a recurring payment, make sure the user is logged in
if form.recurring_payment:
[email_field] = form.fields.filter(field_type__iexact='EmailVerificationField')[:1] or [None]
if request.user.is_anonymous and not email_field:
# anonymous user - if we don't have the email field, redirect to login
response = redirect('auth_login')
response['Location'] += '?next=%s' % form.get_absolute_url()
return response
if request.user.is_superuser and not email_field:
messages.add_message(request, messages.WARNING,
'Please edit the form to include an email field ' +
'as it is required for setting up a recurring ' +
'payment for anonymous users.')
form_for_form = FormForForm(form, request.user, request.POST or None, request.FILES or None)
if form.custom_payment and not form.recurring_payment:
billing_form = BillingForm(request.POST or None)
if request.user.is_authenticated:
billing_form.initial = {
'first_name':request.user.first_name,
'last_name':request.user.last_name,
'email':request.user.email}
else:
billing_form = None
for field in form_for_form.fields:
field_default = request.GET.get(field, None)
if field_default:
form_for_form.fields[field].initial = field_default
if request.method == "POST":
if form_for_form.is_valid() and (not billing_form or billing_form.is_valid()):
entry = form_for_form.save()
entry.entry_path = request.POST.get("entry_path", "")
if request.user.is_anonymous:
if entry.get_email_address():
emailfield = entry.get_email_address()
firstnamefield = entry.get_first_name()
lastnamefield = entry.get_last_name()
phonefield = entry.get_phone_number()
password = ''
for i in range(0, 10):
password += random.choice(string.ascii_lowercase + string.ascii_uppercase)
user_list = User.objects.filter(email=emailfield).order_by('-last_login')
if user_list:
anonymous_creator = user_list[0]
else:
anonymous_creator = User(username=emailfield[:30], email=emailfield,
first_name=firstnamefield, last_name=lastnamefield)
anonymous_creator.set_password(password)
anonymous_creator.is_active = False
anonymous_creator.save()
anonymous_profile = Profile(user=anonymous_creator, owner=anonymous_creator,
creator=anonymous_creator, phone=phonefield)
anonymous_profile.save()
entry.creator = anonymous_creator
else:
entry.creator = request.user
entry.save()
entry.set_group_subscribers()
# Email
subject = generate_email_subject(form, entry)
email_headers = {} # content type specified below
if form.email_from:
email_headers.update({'Reply-To':form.email_from})
# Email to submitter
# fields aren't included in submitter body to prevent spam
submitter_body = generate_submitter_email_body(entry, form_for_form)
email_from = form.email_from or settings.DEFAULT_FROM_EMAIL
email_to = form_for_form.email_to()
is_spam = Email.is_blocked(email_to)
if is_spam:
# log the spam
description = "Email \"{0}\" blocked because it is listed in email_blocks.".format(email_to)
EventLog.objects.log(instance=form, description=description)
if form.completion_url:
return HttpResponseRedirect(form.completion_url)
return redirect("form_sent", form.slug)
email = Email()
email.subject = subject
email.reply_to = form.email_from
if email_to and form.send_email and form.email_text:
# Send message to the person who submitted the form.
email.recipient = email_to
#.........这里部分代码省略.........
示例6: message
# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import recipient [as 别名]
def message(request, group_slug, template_name='user_groups/message.html'):
"""
Send a message to the group
"""
from tendenci.apps.emails.models import Email
group = get_object_or_404(Group, slug=group_slug)
EventLog.objects.log(instance=group)
members = GroupMembership.objects.filter(
group=group,
status=True,
status_detail='active')
num_members = members.count()
form = MessageForm(request.POST or None,
request=request,
num_members=num_members)
if request.method == 'POST' and form.is_valid():
email = Email()
email.sender_display = request.user.get_full_name()
email.sender = get_setting('site', 'global', 'siteemailnoreplyaddress')
email.reply_to = email.sender
email.content_type = 'text/html'
email.subject = form.cleaned_data['subject']
email.body = form.cleaned_data['body']
email.save(request.user)
# send email to myself (testing email)
if form.cleaned_data['is_test']:
email.recipient = request.user.email
email.send()
messages.add_message(
request,
messages.SUCCESS,
_('Successfully sent test email to yourself'))
EventLog.objects.log(instance=email)
else:
# send email to members
for member in members:
email.recipient = member.member.email
email.send()
messages.add_message(
request,
messages.SUCCESS,
_('Successfully sent email to all %(num)s members in this group' % {'num': num_members}))
EventLog.objects.log(instance=email)
return redirect('group.detail', group_slug=group_slug)
else:
print 'form errors', form.errors.items()
return render(request, template_name, {
'group': group,
'num_members': num_members,
'form': form})
示例7: send_newsletter
# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import recipient [as 别名]
def send_newsletter(self, newsletter_id, **kwargs):
from tendenci.apps.emails.models import Email
from tendenci.apps.newsletters.models import Newsletter
from tendenci.apps.site_settings.utils import get_setting
from tendenci.apps.base.utils import validate_email
from tendenci.apps.newsletters.utils import get_newsletter_connection
connection = get_newsletter_connection()
if not connection:
print('Exiting..Please set up your newsletter email provider before proceeding.')
return
print("Started sending newsletter...")
if newsletter_id == 0:
raise CommandError('Newsletter ID is required. Usage: ./manage.py send_newsletter <newsletter_id>')
newsletter = Newsletter.objects.filter(pk=int(newsletter_id))
if newsletter.exists():
newsletter = newsletter[0]
else:
newsletter = None
if not newsletter:
raise CommandError('You are trying to send a newsletter that does not exist.')
if newsletter.send_status == 'queued':
newsletter.send_status = 'sending'
elif newsletter.send_status == 'sent':
newsletter.send_status = 'resending'
elif newsletter.send_status == 'resent':
newsletter.send_status == 'resending'
newsletter.save()
recipients = newsletter.get_recipients()
email = newsletter.email
# replace relative to absolute urls
self.site_url = get_setting('site', 'global', 'siteurl')
email.body = email.body.replace("src=\"/", "src=\"%s/" % self.site_url)
email.body = email.body.replace("href=\"/", "href=\"%s/" % self.site_url)
counter = 0
for recipient in recipients:
# skip if not a valid email address
if not validate_email(recipient.member.email):
continue
subject = email.subject
body = email.body
if '[firstname]' in subject:
subject = subject.replace('[firstname]', recipient.member.first_name)
if '[lastname]' in subject:
subject = subject.replace('[lastname]', recipient.member.last_name)
if '[username]' in body:
body = body.replace('[username]', recipient.member.username)
if '[firstname]' in body:
body = body.replace('[firstname]', recipient.member.first_name)
if '[unsubscribe_url]' in body:
#body = body.replace('[unsubscribe_url]', recipient.noninteractive_unsubscribe_url)
# The unsubscribe_url link should be something like <a href="[unsubscribe_url]">Unsubscribe</a>.
# But it can be messed up sometimes. Let's prevent that from happening.
p = r'(href=\")([^\"]*)(\[unsubscribe_url\])(\")'
body = re.sub(p, r'\1' + recipient.noninteractive_unsubscribe_url + r'\4', body)
if '[browser_view_url]' in body:
body = body.replace('[browser_view_url]', newsletter.get_browser_view_url())
email_to_send = Email(
subject=subject,
body=body,
sender=email.sender,
sender_display=email.sender_display,
reply_to=email.reply_to,
recipient=recipient.member.email
)
print(u"Sending to {}".format(unicode(recipient.member.email)))
email_to_send.send(connection=connection)
counter += 1
print(u"Newsletter sent to {}".format(unicode(recipient.member.email)))
if newsletter.send_to_email2 and hasattr(recipient.member, 'profile') \
and validate_email(recipient.member.profile.email2):
email_to_send.recipient = recipient.member.profile.email2
email_to_send.send(connection=connection)
counter += 1
print(u"Newsletter sent to {}".format(unicode(recipient.member.profile.email2)))
if newsletter.send_status == 'sending':
newsletter.send_status = 'sent'
newsletter.date_email_sent = datetime.datetime.now()
#.........这里部分代码省略.........
示例8: handle
# 需要导入模块: from tendenci.apps.emails.models import Email [as 别名]
# 或者: from tendenci.apps.emails.models.Email import recipient [as 别名]
def handle(self, *args, **options):
import datetime
from tendenci.apps.emails.models import Email
from tendenci.apps.newsletters.models import Newsletter
from tendenci.apps.site_settings.utils import get_setting
from tendenci.apps.newsletters.utils import get_newsletter_connection
connection = get_newsletter_connection()
if not connection:
print('Exiting..Please set up your newsletter email provider before proceeding.')
return
print "Started sending newsletter..."
newsletter_id = options['newsletter_id']
if newsletter_id == 0:
raise CommandError('Newsletter ID is required. Usage: ./manage.py send_newsletter <newsletter_id>')
newsletter = Newsletter.objects.filter(pk=int(newsletter_id))
if newsletter.exists():
newsletter = newsletter[0]
else:
newsletter = None
if not newsletter:
raise CommandError('You are trying to send a newsletter that does not exist.')
if newsletter.send_status == 'queued':
newsletter.send_status = 'sending'
elif newsletter.send_status == 'sent':
newsletter.send_status = 'resending'
elif newsletter.send_status == 'resent':
newsletter.send_status == 'resending'
newsletter.save()
recipients = newsletter.get_recipients()
email = newsletter.email
# replace relative to absolute urls
self.site_url = get_setting('site', 'global', 'siteurl')
email.body = email.body.replace("src=\"/", "src=\"%s/" % self.site_url)
email.body = email.body.replace("href=\"/", "href=\"%s/" % self.site_url)
counter = 0
for recipient in recipients:
subject = email.subject
body = email.body
if '[firstname]' in subject:
subject = subject.replace('[firstname]', recipient.member.first_name)
if '[lastname]' in subject:
subject = subject.replace('[lastname]', recipient.member.last_name)
if '[username]' in body:
body = body.replace('[username]', recipient.member.username)
if '[firstname]' in body:
body = body.replace('[firstname]', recipient.member.first_name)
if '[unsubscribe_url]' in body:
body = body.replace('[unsubscribe_url]', recipient.noninteractive_unsubscribe_url)
if '[browser_view_url]' in body:
body = body.replace('[browser_view_url]', newsletter.get_browser_view_url())
email_to_send = Email(
subject=subject,
body=body,
sender=email.sender,
sender_display=email.sender_display,
reply_to=email.reply_to,
recipient=recipient.member.email
)
email_to_send.send(connection=connection)
counter += 1
print "Newsletter sent to %s" % recipient.member.email
if newsletter.send_to_email2 and hasattr(recipient.member, 'profile') \
and recipient.member.profile.email2:
email_to_send.recipient = recipient.member.profile.email2
email_to_send.send(connection=connection)
counter += 1
print "Newsletter sent to %s" % recipient.member.profile.email2
if newsletter.send_status == 'sending':
newsletter.send_status = 'sent'
newsletter.date_email_sent = datetime.datetime.now()
elif newsletter.send_status == 'resending':
newsletter.send_status = 'resent'
newsletter.date_last_resent = datetime.datetime.now()
if not newsletter.resend_count:
newsletter.resend_count = 0
newsletter.resend_count += 1
#.........这里部分代码省略.........