MCPcopy
hub / github.com/django/django / message

Method message

django/core/mail/message.py:339–367  ·  view source on GitHub ↗
(self, *, policy=email.policy.default)

Source from the content-addressed store, hash-verified

337 self._connection = value
338
339 def message(self, *, policy=email.policy.default):
340 msg = email.message.EmailMessage(policy=policy)
341 self._add_bodies(msg)
342 self._add_attachments(msg)
343
344 msg["Subject"] = str(self.subject)
345 msg["From"] = str(self.extra_headers.get("From", self.from_email))
346 self._set_list_header_if_not_empty(msg, "To", self.to)
347 self._set_list_header_if_not_empty(msg, "Cc", self.cc)
348 self._set_list_header_if_not_empty(msg, "Reply-To", self.reply_to)
349
350 # Email header names are case-insensitive (RFC 2045), so we have to
351 # accommodate that when doing comparisons.
352 header_names = [key.lower() for key in self.extra_headers]
353 if "date" not in header_names:
354 if settings.EMAIL_USE_LOCALTIME:
355 tz = get_current_timezone()
356 else:
357 tz = timezone.utc
358 msg["Date"] = datetime.now(tz)
359 if "message-id" not in header_names:
360 # Use cached DNS_NAME for performance
361 msg["Message-ID"] = make_msgid(domain=DNS_NAME)
362 for name, value in self.extra_headers.items():
363 # Avoid headers handled above.
364 if name.lower() not in {"from", "to", "cc", "reply-to"}:
365 msg[name] = force_str(value, strings_only=True)
366 self._idna_encode_address_header_domains(msg)
367 return msg
368
369 def recipients(self):
370 """

Calls 9

_add_bodiesMethod · 0.95
_add_attachmentsMethod · 0.95
get_current_timezoneFunction · 0.90
force_strFunction · 0.90
getMethod · 0.45
nowMethod · 0.45
itemsMethod · 0.45