2
2
import re
3
3
from typing import Dict , TypeVar , Generic , Dict , Any , cast # NOQA
4
4
from django .utils .safestring import SafeString
5
- from django .core .mail import EmailMultiAlternatives
5
+ from django .core .mail import EmailMultiAlternatives , EmailMessage
6
6
from django .template .loader import render_to_string
7
7
from django .utils .html import strip_tags
8
8
@@ -64,7 +64,7 @@ def subject(self) -> str:
64
64
:py:meth:`str.format` and passed the same context that is
65
65
passed to templates when rendering the email, so you can
66
66
include context variables via brace notation, e.g.
67
- ``Hello {full_name}!``.
67
+ ``" Hello {full_name}!" ``.
68
68
'''
69
69
70
70
pass # pragma: no cover
@@ -74,7 +74,7 @@ def subject(self) -> str:
74
74
def template_name (self ) -> str :
75
75
'''
76
76
The path to the template used to render the email, e.g.
77
- ``my_app/my_email.html``.
77
+ ``" my_app/my_email.html" ``.
78
78
'''
79
79
80
80
pass # pragma: no cover
@@ -109,14 +109,17 @@ def render_body_as_html(self, ctx: T) -> SafeString:
109
109
def render_subject (self , ctx : T ) -> str :
110
110
return self .subject .format (** self ._cast_to_dict (ctx ))
111
111
112
- def send_messages (self , ctx : T , from_email = None , to = None , bcc = None ,
113
- connection = None , attachments = None , headers = None ,
114
- alternatives = None , cc = None , reply_to = None ) -> int :
112
+ def create_message (self , ctx : T , from_email = None , to = None , bcc = None ,
113
+ connection = None , attachments = None , headers = None ,
114
+ alternatives = None , cc = None ,
115
+ reply_to = None ) -> EmailMessage :
115
116
'''
116
- Renders the email using context specified by ``ctx`` and sends it.
117
+ Creates and returns a :py:class:`django.core.mail.EmailMessage`
118
+ which contains the plaintext and HTML versions of the email,
119
+ using the context specified by ``ctx``.
117
120
118
121
Aside from ``ctx``, arguments to this method are the
119
- same as those for :py:class:`django.core.mail.EmailMessage`.
122
+ same as those for :py:class:`~ django.core.mail.EmailMessage`.
120
123
'''
121
124
122
125
msg = EmailMultiAlternatives (
@@ -133,4 +136,4 @@ def send_messages(self, ctx: T, from_email=None, to=None, bcc=None,
133
136
reply_to = reply_to ,
134
137
)
135
138
msg .attach_alternative (self .render_body_as_html (ctx ), 'text/html' )
136
- return msg . send ( fail_silently = False )
139
+ return msg
0 commit comments