def test_unicode_simple_message(self): charset = 'utf-8' msg1 = MIMEText( '''По оживлённым берегам Громады стройные теснятся Дворцов и башен; корабли Толпой со всех концов земли К богатым пристаням стремятся;'''.encode(charset), 'plain', charset) msg1['Message-ID'] = '<*****@*****.**>' s_msg = msg1.as_string() msg2 = parse_message(s_msg) assert isinstance(msg2['payload'], six.text_type) assert_in('всех', msg2['payload'])
def send(self, recipients, subject, body, sender=None, **kwargs): # type: (str, str, str, Optional[str], ...) -> None """ Send email Args: recipient (str): Email recipient subject (str): Email subject body (str): Email body sender (Optional[str]): Email sender. Defaults to SMTP username. **kwargs: See below mail_options (list): Mail options (see smtplib documentation) rcpt_options (list): Recipient options (see smtplib documentation) Returns: None """ if sender is None: sender = self.username v = validate_email(sender, check_deliverability=False) # validate and get info sender = v['email'] # replace with normalized form normalised_recipients = list() for recipient in recipients: v = validate_email(recipient, check_deliverability=True) # validate and get info normalised_recipients.append(v['email']) # replace with normalized form msg = MIMEText(body) msg['Subject'] = subject msg['From'] = sender msg['To'] = ', '.join(normalised_recipients) # Perform operations via server self.connect() self.server.sendmail(sender, normalised_recipients, msg.as_string(), **kwargs) self.close()