def send(self):
if self.content_type.name == '<STR_LIT>':<EOL><INDENT>to = [self.to.user.email]<EOL><DEDENT>elif self.content_type.name == '<STR_LIT>':<EOL><INDENT>to = [self.to.email]<EOL>for mantainer in self.to.mantainers.all().only('<STR_LIT:email>'):<EOL><INDENT>to += [mantainer.email]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>to = [self.to.email]<EOL><DEDENT>context = {<EOL>'<STR_LIT>': self.from_name,<EOL>'<STR_LIT>': self.from_email,<EOL>'<STR_LIT:message>': self.message,<EOL>'<STR_LIT>': settings.SITE_NAME,<EOL>'<STR_LIT>': self.content_type.name,<EOL>'<STR_LIT:object_name>': str(self.to)<EOL>}<EOL>message = render_to_string('<STR_LIT>', context)<EOL>email = EmailMessage(<EOL>_('<STR_LIT>') % context,<EOL>message,<EOL>settings.DEFAULT_FROM_EMAIL,<EOL>to,<EOL>headers={'<STR_LIT>': self.from_email}<EOL>)<EOL>import socket<EOL>try:<EOL><INDENT>email.send()<EOL>self.status = <NUM_LIT:1><EOL><DEDENT>except socket.error as e:<EOL><INDENT>import logging<EOL>log = logging.getLogger(__name__)<EOL>error_msg = '<STR_LIT>' % e<EOL>log.error(error_msg)<EOL>self.status = -<NUM_LIT:1><EOL><DEDENT>
Sends the email to the recipient
If the sending fails will set the status of the instance to "error" and will log the error according to your project's django-logging configuration