def as_string(self, default_from=None):
encoding = self.charset or '<STR_LIT:utf-8>'<EOL>attachments = self.attachments or []<EOL>if len(attachments) == <NUM_LIT:0> and not self.html:<EOL><INDENT>msg = self._mimetext(self.body)<EOL><DEDENT>elif len(attachments) > <NUM_LIT:0> and not self.html:<EOL><INDENT>msg = MIMEMultipart()<EOL>msg.attach(self._mimetext(self.body))<EOL><DEDENT>else:<EOL><INDENT>msg = MIMEMultipart()<EOL>alternative = MIMEMultipart('<STR_LIT>')<EOL>alternative.attach(self._mimetext(self.body, '<STR_LIT>'))<EOL>alternative.attach(self._mimetext(self.html, '<STR_LIT:html>'))<EOL>msg.attach(alternative)<EOL><DEDENT>if self.charset:<EOL><INDENT>msg['<STR_LIT>'] = Header(self.subject, encoding)<EOL><DEDENT>else:<EOL><INDENT>msg['<STR_LIT>'] = self.subject<EOL><DEDENT>sender = self.sender or default_from<EOL>if sender is not None:<EOL><INDENT>msg['<STR_LIT>'] = sanitize_address(sender, encoding)<EOL><DEDENT>msg['<STR_LIT>'] = '<STR_LIT:U+002CU+0020>'.join(list(set(sanitize_addresses(self.recipients, encoding))))<EOL>msg['<STR_LIT>'] = formatdate(self.date, localtime=True)<EOL>msg['<STR_LIT>'] = self.msgId<EOL>if self.cc:<EOL><INDENT>msg['<STR_LIT>'] = '<STR_LIT:U+002CU+0020>'.join(list(set(sanitize_addresses(self.cc, encoding))))<EOL><DEDENT>if self.reply_to:<EOL><INDENT>msg['<STR_LIT>'] = sanitize_address(self.reply_to, encoding)<EOL><DEDENT>if self.extra_headers:<EOL><INDENT>for k, v in self.extra_headers.items():<EOL><INDENT>msg[k] = v<EOL><DEDENT><DEDENT>for attachment in attachments:<EOL><INDENT>f = MIMEBase(*attachment.content_type.split('<STR_LIT:/>'))<EOL>f.set_payload(attachment.data)<EOL>encode_base64(f)<EOL>try:<EOL><INDENT>attachment.filename and attachment.filename.encode('<STR_LIT:ascii>')<EOL><DEDENT>except UnicodeEncodeError:<EOL><INDENT>filename = attachment.filename<EOL>if not PY3:<EOL><INDENT>filename = filename.encode('<STR_LIT:utf8>')<EOL><DEDENT>f.add_header('<STR_LIT>', attachment.disposition,<EOL>filename=('<STR_LIT>', '<STR_LIT>', filename))<EOL><DEDENT>else:<EOL><INDENT>f.add_header('<STR_LIT>', '<STR_LIT>' %<EOL>(attachment.disposition, attachment.filename))<EOL><DEDENT>for key, value in attachment.headers:<EOL><INDENT>f.add_header(key, value)<EOL><DEDENT>msg.attach(f)<EOL><DEDENT>return msg.as_string()<EOL>
Creates the email