示例#1
0
def generate_email(to,
                   from_addr,
                   subject,
                   template,
                   html_template,
                   context={},
                   bcc=None,
                   registration=None):
    if registration:
        subject = subject if not registration.test else '***Test*** ' + subject
    context['site_url'] = settings.SITE_URL
    html = render_to_string(html_template, context)
    body = render_to_string(template, context)
    message = MailerMessage(to_address=', '.join(to),
                            from_address=from_addr,
                            subject=subject,
                            content=body,
                            html_content=html)
    if bcc:
        if isinstance(bcc, basestring):
            message.bcc_address = bcc
        elif isinstance(bcc, (list, tuple)):
            message.bcc_address = ', '.join(bcc)


#     msg = EmailMultiAlternatives(subject, body, from_addr, to, bcc)
#     msg.attach_alternative(html, 'text/html')
    return message
def send_text_email(to,from_addr,subject,body,context={},cc=[],bcc=[],registration=None):
    body = render_to_string(body,context)
    message = MailerMessage(to_address=', '.join(to),from_address=from_addr,subject=subject,content=body)
    if bcc:
        if isinstance(bcc, basestring):
            message.bcc_address = bcc
        elif isinstance(bcc, (list, tuple)):
            message.bcc_address = ', '.join(bcc)
    message.save()
    if registration:
        registration.email_messages.add(message)
        registration.save()
    return message
示例#3
0
def dynamic_form_send_confirmation_email(form_model, form, advert, request):
    from django.template import Template, Context

    ctx = {"ad": advert, "advert": advert}

    if advert.confirmation_email_subject:
        subject = Template(advert.confirmation_email_subject).render(Context(ctx))
    else:
        subject = advert.title
    if advert.confirmation_email:
        message = Template(advert.confirmation_email).render(Context(ctx))
    else:
        message = render_to_string("dynamic_forms/confirmation_email.txt", ctx)

    new_message = MailerMessage()
    new_message.subject = subject
    new_message.to_address = form.cleaned_data["email"]
    new_message.bcc_address = (
        "%s, [email protected]" % advert.advertiser.roof_contact
    )  # settings.DYNAMIC_FORMS_EMAIL_HIDDEN_RECIPIENTS
    new_message.reply_to = advert.advertiser.email
    new_message.from_address = "*****@*****.**"
    new_message.from_name = "Roof Media"
    new_message.content = ""
    new_message.html_content = message
    new_message.app = "dynamic_forms"
    new_message.save()
示例#4
0
def dynamic_form_send_email(form_model, form, advert, request):

    mapped_data = form.get_mapped_data()

    ctx = {"form_model": form_model, "form": form, "data": sorted(mapped_data.items()), "ad": advert}
    if advert.notification_email_subject:
        subject = Template(advert.notification_email_subject).render(Context(ctx))
    else:
        subject = _("Has recibido una nueva oportunidad de venta")
    if advert.notification_email:

        message = Template(advert.notification_email).render(Context(ctx))

    else:

        message = render_to_string("dynamic_forms/notification_email.txt", ctx)

    new_message = MailerMessage()
    new_message.subject = subject
    new_message.to_address = advert.advertiser.email
    new_message.bcc_address = (
        "%s, [email protected]" % advert.advertiser.roof_contact
    )  # settings.DYNAMIC_FORMS_EMAIL_HIDDEN_RECIPIENTS
    new_message.from_address = "*****@*****.**"
    new_message.from_name = "Roof Media"
    new_message.content = ""
    new_message.html_content = message
    new_message.app = "dynamic_forms"
    new_message.save()
示例#5
0
def send_email(to_address,
               subject,
               content,
               html_content,
               bcc_address=None,
               attachment=None,
               attachment2=None,
               attachment3=None):
    new_message = MailerMessage()
    new_message.subject = subject
    new_message.to_address = to_address

    if bcc_address:
        new_message.bcc_address = bcc_address

    new_message.from_address = settings.DEFAULT_FROM_EMAIL
    new_message.content = content
    new_message.html_content = html_content
    new_message.cc_address = settings.DEFAULT_CC_EMAIL
    if attachment:
        new_message.add_attachment(attachment)
    if attachment2:
        new_message.add_attachment(attachment2)
    if attachment3:
        new_message.add_attachment(attachment3)
    new_message.app = "our app name"
    new_message.save()
示例#6
0
def registration_invoice_finish(request):
	from invoice.models import Invoice
	from bookings.models import BookingLine
	from mailqueue.models import MailerMessage
	from survey.actions import MailSenderParticipantSurvey


	session_invoice_id = request.session['paid_invoice_id']

	invoice = Invoice.objects.get(pk=session_invoice_id)
	receiver = invoice.address.billing_email

	survey_link = None
	billed_participant = invoice.billed_participant()

	context = {'handle': invoice.handle,
		'number': invoice.number,
		'hostname': request.scheme + "://" + request.get_host(),
		'receiver' : receiver,
		'billed_participant': billed_participant,
		}

	if not invoice.mail_sent_at:

		subject = render_to_string('ewtisite/email_invoice_paid/subject.txt', context)
		msg_text = render_to_string('ewtisite/email_invoice_paid/text.txt', context)
		#receiver = invoice.address.billing_email

		new_message = MailerMessage()
		new_message.subject = subject
		new_message.to_address = receiver
		new_message.from_address = settings.EMAIL_SENDER_ADDRESS
		new_message.bcc_address = settings.SHOP_NOTICE_MAILS_TO
		new_message.content = msg_text
		new_message.app = "EWTI Billing"
		new_message.save()

		entered_bookinglines = invoice.bookingline_set.all()
		for bl in entered_bookinglines:
			p = bl.participant

			ms = MailSenderParticipantSurvey()
			ms.context = {
				'participant':p,
				'hostname': request.scheme + "://" + request.get_host(),
				}
			ms.from_address = settings.EMAIL_SENDER_ADDRESS
			ms.bcc_address = settings.SHOP_NOTICE_MAILS_TO
			ms.to_address = p.email
			ms.send()

		invoice.mail_sent_at = datetime.now()
		invoice.save()



	return render(request, 'ewtisite/register_invoice_finish.html', context)
示例#7
0
def send_text_email(to,from_addr,subject,body,context={},cc=[],bcc=[],registration=None):
    body = render_to_string(body,context)
    message = MailerMessage(to_address=', '.join(to),from_address=from_addr,subject=subject,content=body)
    if bcc:
        message.bcc_address = ', '.join(bcc)
    message.save()
    if registration:
        registration.email_messages.add(message)
        registration.save()
    return message
示例#8
0
def sendmail(singername, receiver, title, url, time):
    new_message = MailerMessage()
    new_message.subject = singername + "演唱會資訊 from Hiticket"
    new_message.to_address = receiver
    new_message.bcc_address = ""
    new_message.from_address = "*****@*****.**"
    new_message.content = ""
    new_message.html_content = "哈囉, 有新的一筆關於" + singername + "演唱會的資料如下:<br><br> \n\n  時間:  " + time + "<br>\n  Title:  " + title + "<br>\n  Link:  " + url
    new_message.app = "Name of your App that is sending the email."
    new_message.save()
示例#9
0
def generate_email(to,from_addr,subject,template,html_template,context={},bcc=None,registration=None):
    if registration:
        subject = subject if not registration.test else '***Test*** '+subject
    context['site_url'] = settings.SITE_URL
    html = render_to_string(html_template,context)
    body = render_to_string(template,context)
    message = MailerMessage(to_address=', '.join(to),from_address=from_addr,subject=subject,content=body,html_content=html)
    if bcc:
        message.bcc_address = ', '.join(bcc)
#     msg = EmailMultiAlternatives(subject, body, from_addr, to, bcc)
#     msg.attach_alternative(html, 'text/html')
    return message
示例#10
0
def create_mail_message(request):
    new_message = MailerMessage()
    new_message.subject = "My Subject"
    new_message.to_address = "*****@*****.**"
    new_message.bcc_address = "*****@*****.**"
    new_message.from_address = "*****@*****.**"
    new_message.content = "Mail content"
    new_message.html_content = "<h1>Mail Content</h1>"
    new_message.app = "Name of your App that is sending the email."
    new_message.save()

    return render(request, 'index.html')
 def _setup_email(self):
     msg = MailerMessage()
     msg.from_address = self.from_address
     msg.to_address = self._get_formatted_recipients(self.to)
     if self.cc:
         msg.cc_address = self._get_formatted_recipients(self.cc)
     full_bcc = self._get_bcc_with_debugging_copy()
     if full_bcc:
         msg.bcc_address = self._get_formatted_recipients(full_bcc)
     msg.subject = self.get_rendered_subject()
     msg.html_content = self.get_rendered_html_body()
     msg.content = self.get_plain_text_body()
     msg.app = self.mail.text_identifier
     return msg
示例#12
0
	def send(self):
		self.prepare_content()
		
		subject = self.content['Mailsubject']
		msg_text = self.content['Mailtext']
		
		new_message = MailerMessage()
		new_message.subject = subject
		new_message.to_address = self.to_address
		new_message.from_address = self.from_address
		if self.bcc_address:
			new_message.bcc_address = self.bcc_address
		new_message.content = msg_text
		new_message.app = "EWTI Survey Invitation"
		new_message.save()
示例#13
0
def dynamic_form_send_download_email(form_model, form, advert, request):
    from content.models import DownloadLink
    import hashlib
    import random

    salt2 = "".join(["{0}".format(random.randrange(10)) for i in range(10)])
    key = hashlib.md5("{0}{1}".format(salt2, advert.file.name)).hexdigest()

    src = "/".join([settings.MEDIA_ROOT, advert.file.name])

    download_root = os.path.join(settings.MEDIA_ROOT, "downloads")
    download_url = os.path.join(settings.MEDIA_URL, "downloads")

    dst = os.path.join(download_root, key + ".pdf")
    dst_url = os.path.join(download_url, key + ".pdf")
    link = DownloadLink(key=key, ad=advert, url=dst_url, filepath=dst)
    site_url = request.build_absolute_uri("/")
    dl_url = site_url[:-1] + dst_url
    request.META["DL_URL"] = dl_url
    ctx = {"dl_url": dl_url, "ad": advert}

    if advert.confirmation_email_subject:
        subject = Template(advert.confirmation_email_subject).render(Context({"ad": advert}))
    else:
        subject = _("Descarga: “%(advert)s”") % {"advert": advert.title}
    if advert.confirmation_email:
        message = Template(advert.confirmation_email).render(Context(ctx))
    else:
        message = render_to_string("dynamic_forms/download_email.txt", ctx)

    new_message = MailerMessage()
    new_message.subject = subject
    new_message.to_address = form.cleaned_data["email"]
    new_message.bcc_address = (
        "%s, [email protected]" % advert.advertiser.roof_contact
    )  # settings.DYNAMIC_FORMS_EMAIL_HIDDEN_RECIPIENTS
    new_message.reply_to = advert.advertiser.email
    new_message.from_address = "*****@*****.**"
    new_message.from_name = "Roof Media"
    new_message.content = ""
    new_message.html_content = message
    new_message.app = "dynamic_forms"
    new_message.save()

    link.save()
    if not os.path.isdir(os.path.dirname(dst)):
        os.makedirs(os.path.dirname(dst))
    os.symlink(src, dst)
示例#14
0
 def form_valid(self, form):
     logger.info(
         str(self.request.user) +
         " just sent an email to the whole EESTEC Community: " +
         form.cleaned_data['message'])
     message = MailerMessage()
     message.subject = form.cleaned_data['subject']
     message.content = form.cleaned_data['message']
     message.from_address = "*****@*****.**"
     message.to_address = "*****@*****.**"
     message.bcc_address = ", ".join(
         user.email
         for user in Eestecer.objects.filter(receive_eestec_active=True))
     message.save()
     messages.add_message(self.request, messages.INFO,
                          "Message will be sent now.")
     return redirect("/")
示例#15
0
 def form_valid(self, form):
     logger.info(str(
         self.request.user) + " just sent an email to all privileged members of the EESTEC Community: " +
                 form.cleaned_data['message'])
     message = MailerMessage()
     message.subject = form.cleaned_data['subject']
     message.content = form.cleaned_data['message']
     message.from_address = "*****@*****.**"
     message.to_address = "*****@*****.**"
     message.bcc_address = ", ".join(
         user.email for user in Eestecer.objects.filter(groups__name="Local Admins"))
     message.save()
     messages.add_message(
         self.request,
         messages.INFO, "Message will be sent now."
     )
     return redirect("/")
示例#16
0
 def form_valid(self, form):
     logger.info(str(
         self.request.user) + " just sent an email to the whole EESTEC Community: " +
                 form.cleaned_data['message'])
     message = MailerMessage()
     message.subject = form.cleaned_data['subject']
     message.content = form.cleaned_data['message']
     message.from_address = "*****@*****.**"
     message.to_address = "*****@*****.**"
     message.bcc_address = ", ".join(
         user.email for user in Eestecer.objects.filter(receive_eestec_active=True))
     message.save()
     messages.add_message(
         self.request,
         messages.INFO, "Message will be sent now."
     )
     return redirect("/")
示例#17
0
 def form_valid(self, form):
     logger.info(
         str(self.request.user) +
         " just sent an email to all privileged members of the EESTEC Community: "
         + form.cleaned_data['message'])
     message = MailerMessage()
     message.subject = form.cleaned_data['subject']
     message.content = form.cleaned_data['message']
     message.from_address = "*****@*****.**"
     message.to_address = "*****@*****.**"
     message.bcc_address = ", ".join(
         user.email
         for user in Eestecer.objects.filter(groups__name="Local Admins"))
     message.save()
     messages.add_message(self.request, messages.INFO,
                          "Message will be sent now.")
     return redirect("/")
示例#18
0
def send_announcement(announcement, courseevent, module):
    """
    Send an announcement: it is send to the teachers and the particpants.
    Mentoki is set on CC. Sending uses django-mailqueue, so that send out
    emails are als stored in the database.
    """
    participants_emails = \
        list(CourseEventParticipation.objects.learners_emails(courseevent=courseevent))
    teachers_emails = \
        list(CourseOwner.objects.teachers_emails(course=courseevent.course))
    all_emails = participants_emails + teachers_emails
    send_all = ", ".join(all_emails)

    context = {
        'site': Site.objects.get_current(),
        'courseevent': courseevent,
        'announcement': announcement,
        'owners': courseevent.teachers,
        'betreff': "Neue Nachricht von Mentoki %s" % courseevent.title
    }
    message = get_template('email/announcement/announcement.html').render(
        Context(context))

    mail_message = MailerMessage()

    mail_message.subject = "Neue Nachricht von %s" % courseevent.title
    mail_message.bcc_address = settings.MENTOKI_COURSE_EMAIL
    mail_message.to_address = send_all
    mail_message.from_address = settings.MENTOKI_COURSE_EMAIL
    mail_message.content = "Neue Nachricht von %s and die Teilnehmer" % courseevent.title
    mail_message.html_content = message
    mail_message.reply_to = send_all
    mail_message.app = module

    mail_distributer = send_all
    logger.info("[%s] [Ankündigung %s %s]: als email verschickt an %s" %
                (courseevent, announcement.id, announcement, mail_distributer))
    mail_message.save()
    return mail_distributer
示例#19
0
import sys, os

sys.path.append(os.path.join(os.path.dirname(__file__) + '../', 'web'))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "web.settings")
from django.conf import settings
from mailqueue.models import MailerMessage

new_message = MailerMessage()
new_message.subject = "My Subject"
new_message.to_address = "*****@*****.**"
new_message.bcc_address = ""
new_message.from_address = "*****@*****.**"
new_message.content = "Mail content"
new_message.html_content = "<h1>Mail Content</h1>"
new_message.app = "Name of your App that is sending the email."
new_message.save()