def _create_mail(self, email):
        """A helper method that creates mail for sending."""
        if not email.recipients():
            return False

        from_email = sanitize_address(email.from_email, email.encoding)
        recipients = [sanitize_address(addr, email.encoding)
                      for addr in email.recipients()]

        mail = sendgrid.Mail()
        mail.add_to(recipients)
        mail.add_cc(email.cc)
        mail.add_bcc(email.bcc)
        mail.set_text(email.body)
        mail.set_subject(email.subject)
        mail.set_from(from_email)

        if isinstance(email, EmailMultiAlternatives):
            for alt in email.alternatives:
                if alt[1] == "text/html":
                    mail.set_html(alt[0])

        for attachment in email.attachments:
            if isinstance(attachment, MIMEBase):
                mail.add_attachment_stream(
                    attachment.get_filename(),
                    attachment.get_payload())
            elif isinstance(attachment, tuple):
                mail.add_attachment_stream(attachment[0], attachment[1])

        return mail
dataset/ETHPy150Open crowdresearch/crowdsource-platform/crowdsourcing/backends/sendgrid_backend.py/SendGridBackend._create_mail/original