Ticket #5963: render_to_mail.diff
File render_to_mail.diff, 3.3 KB (added by , 17 years ago) |
---|
-
django/core/mail.py
314 314 """Attach an alternative content representation.""" 315 315 self.attach(content=content, mimetype=mimetype) 316 316 317 def send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=None, auth_password=None ):317 def send_mail(subject, message, from_email, recipient_list, fail_silently=False, auth_user=None, auth_password=None, auto_send=True): 318 318 """ 319 319 Easy wrapper for sending a single message to a recipient list. All members 320 320 of the recipient list will see the other recipients in the 'To' field. … … 327 327 """ 328 328 connection = SMTPConnection(username=auth_user, password=auth_password, 329 329 fail_silently=fail_silently) 330 return EmailMessage(subject, message, from_email, recipient_list, connection=connection).send()330 email_obj = EmailMessage(subject, message, from_email, recipient_list, connection=connection) 331 331 332 if auto_send: 333 return email_obj.send() 334 335 # Returns email message object if auto_send is not True 336 else: 337 return email_obj 338 332 339 def send_mass_mail(datatuple, fail_silently=False, auth_user=None, auth_password=None): 333 340 """ 334 341 Given a datatuple of (subject, message, from_email, recipient_list), sends -
django/shortcuts/__init__.py
8 8 from django.http import HttpResponse, Http404 9 9 from django.db.models.manager import Manager 10 10 from django.db.models.query import QuerySet 11 from django.core.mail import send_mail 12 from django.conf import settings 13 from django.template import Context 14 from django.template.loader import get_template 11 15 12 16 def render_to_response(*args, **kwargs): 13 17 """ … … 17 21 httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)} 18 22 return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs) 19 23 24 def render_to_mail(template_path, params, subject, from_email=None, recipient_list=[], auth_user=None, auth_password=None, fail_silently=False, content_subtype=None, attachments=[], **kwargs): 25 """ 26 Sends a e-mail message with content parsed from a template. The syntax is 27 the same of render_to_response function. 28 Returns then boolean of mail sending, using core.mail.send_mail function. 29 """ 30 content_subtype = content_subtype or getattr(settings, 'DEFAULT_EMAIL_CONTENT_SUBTYPE', 'html') 31 from_email = from_email or getattr(settings, 'DEFAULT_FROM_EMAIL', None) 32 33 if not recipient_list: 34 return False 35 36 # Loads template for mail content 37 t = get_template(template_path) 38 39 # Render content 40 message = t.render(Context(params)) 41 42 # Email object 43 email_obj = send_mail(subject, message, from_email, recipient_list, fail_silently, auth_user, auth_password) 44 45 email_obj.content_subtype = content_subtype 46 47 if attachments: 48 for att in attachments: 49 email_obj.attach_file(att) 50 51 return email_obj.send() 52 20 53 def _get_queryset(klass): 21 54 """ 22 55 Returns a QuerySet from a Model, Manager, or QuerySet. Created to make