def handle(self, *args, **options): logger.info('Acquiring lock for sending queued emails at %s.lock' % options['lockfile']) mail.send( ['*****@*****.**'], # List of email addresses also accepted '*****@*****.**', subject='Welcome!', html_message=render_to_string('project_a/test.html', {'data':{'Ashok':[('Band', 1),\ ('Tood', 2)],'Khan': [('Mat', 6),('Rat', 7)], 'Ash': [('Cool', 3) , ('Float', 4), ('Loop', 5)]}}), # scheduled_time=date(2014, 1, 1), headers={'Reply-to': '*****@*****.**', 'Content-Type':'text/html'}, context={'name': 'Alice'}, ) try: with FileLock(options['lockfile']): while 1: try: send_queued(options['processes'], options.get('log_level')) except Exception as e: logger.error(e, exc_info=sys.exc_info(), extra={'status_code': 500}) raise # Close DB connection to avoid multiprocessing errors connection.close() if not Email.objects.filter(status=STATUS.queued) \ .filter(Q(scheduled_time__lte=now()) | Q(scheduled_time=None)).exists(): break except FileLocked: logger.info('Failed to acquire lock, terminating now.')
def handle(self, *args, **options): """ Bulk send reminder emails. """ today = datetime.date.today().weekday() all_dashboard = Dashboard.objects.all() all_emails = [] for d in all_dashboard: # Advisory period completed. So skip it if d.advisory_end_date < datetime.date.today(): continue url = 'http://ashoka-dashboard.herokuapp.com' \ + d.consultant_form_url all_teams = d.teams.filter( reminder_emails_day=today).select_related() for team in all_teams: # Add automatic reminder only if automatic_reminder is true if not team.team_status.automatic_reminder: continue # Get all Pulse Checkers and LRPs recipients = team.members.filter( Q(secondary_role__short_name="PC") or Q(role__short_name="LRP") ).distinct() if recipients: to = [r['email'] for r in recipients.values('email').all()] all_emails.append({ 'recipients': to, 'template': 'reminder_email', 'context': {'data': url}, }) # Queue all reminder emails at once mail.send_many(all_emails) # Send all queued emails mail.send_queued()
def __check_send_email(tpl_name, content=None): email = mail.from_template( "*****@*****.**", user.email, template=tpl_name, context=dict(user=user)) self.assertEqual(Email.objects.get(id=email.id).status, STATUS.queued) mail.send_queued() self.assertEqual(Email.objects.get(id=email.id).status, STATUS.sent) if content: for field in content.iterkeys(): self.assertIn(content[field], getattr(email, field))
def enviar_notificação_de_email(self): """Notifica inscritos no boletim de notícias a respeito da criação de um novo artigo.""" def construir_email(email): """Controe um email para ser enviado por mail.send_many.""" return { 'recipients': [email], 'template': 'artigo_criado', 'context': {'artigo': self, 'site': Site.objects.get_current()} } emails = map(lambda inscrito: construir_email(inscrito.email), Inscrito.objects.filter(ativo=True)) mail.send_many(emails) mail.send_queued()
def __check_send_email(tpl_name, content=None): email = mail.from_template("*****@*****.**", user.email, template=tpl_name, context=dict(user=user)) self.assertEqual( Email.objects.get(id=email.id).status, STATUS.queued) mail.send_queued() self.assertEqual( Email.objects.get(id=email.id).status, STATUS.sent) if content: for field in content.iterkeys(): self.assertIn(content[field], getattr(email, field))
def test_send_with_html_template(self): template = EmailTemplate.objects.create( name="Test Inlined Images", subject="[django-SHOP unit tests] attached image", html_content=""" {% load post_office %} <h3>Testing image attachments</h3> <img src="{% inline_image imgsrc %}" width="200" />""" ) filename = os.path.join(os.path.dirname(__file__), 'static/dummy.png') context = {'imgsrc': filename} queued_mail = send(recipients=['*****@*****.**'], sender='*****@*****.**', template=template, context=context, render_on_delivery=True) queued_mail = Email.objects.get(id=queued_mail.id) send_queued() self.assertEqual(Email.objects.get(id=queued_mail.id).status, STATUS.sent)
def send_queued_mail(*args, **kwargs): send_queued()
def send_regular_emails_task(): mail.send_queued()
def send_queued_mail(*args, **kwargs): """ Celery task """ send_queued()
def send_queued_mail(processes=1): """ Send all email queued by django-post_office once a minute. """ from post_office.mail import send_queued send_queued(processes)
#~ from django.core.mail import send_mail #~ send_mail( #~ 'Subject here', #~ 'Here is the message.', #~ '*****@*****.**', #~ ['*****@*****.**'], #~ fail_silently=False, #~ ) from post_office import mail mail.send( ['*****@*****.**'], '*****@*****.**', subject='My email', message='Hi there!', html_message='Hi <strong>there</strong>!', ) mail.send_queued()
def sendEmail(): mail.send_queued()
def send_queued_emails(): return send_queued()