我们从Python开源项目中,提取了以下29个代码示例,用于说明如何使用django.core.mail.message.sanitize_address()。
def _send(self, email_message): """A helper method that does the actual sending.""" if not email_message.recipients(): return False from_email = sanitize_address(email_message.from_email, email_message.encoding) recipients = [sanitize_address(addr, email_message.encoding) for addr in email_message.recipients()] message = email_message.message() charset = message.get_charset().get_output_charset() if message.get_charset() else 'utf-8' try: self.connection.sendmail(from_email, recipients, force_bytes(message.as_string(), charset)) except: if not self.fail_silently: raise return False return True
def formataddr(self, encoding=None): """Return a fully-formatted email address, using encoding. This is essentially the same as :func:`email.utils.formataddr` on the EmailAddress's name and email properties, but uses Django's :func:`~django.core.mail.message.sanitize_address` for improved PY2/3 compatibility, consistent handling of encoding (a.k.a. charset), and proper handling of IDN domain portions. :param str|None encoding: the charset to use for the display-name portion; default None uses ascii if possible, else 'utf-8' (quoted-printable utf-8/base64) """ return sanitize_address((self.display_name, self.addr_spec), encoding)
def _send(self, email_message): """A helper method that does the actual sending.""" if not email_message.recipients(): return False from_email = sanitize_address(email_message.from_email, email_message.encoding) recipients = [sanitize_address(addr, email_message.encoding) for addr in email_message.recipients()] message = email_message.message() try: self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='\r\n')) except smtplib.SMTPException: if not self.fail_silently: raise return False return True
def _send(self, email_message): """A helper method that does the actual sending.""" if not email_message.recipients(): return False encoding = email_message.encoding or settings.DEFAULT_CHARSET from_email = sanitize_address(email_message.from_email, encoding) recipients = [sanitize_address(addr, encoding) for addr in email_message.recipients()] message = email_message.message() try: self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='\r\n')) except smtplib.SMTPException: if not self.fail_silently: raise return False return True