<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def send_messages(self, emails):
 """ Attempt to send the specified emails. """

        num_sent = 0
        for e in emails:
            html = None
            if isinstance(e, EmailMultiAlternatives):
                for a in e.alternatives:
                    if a[1] == 'text/html':
                        html = a[0]
            r = self._connection.send(
                from_=e.from_email,
                to=e.to,
                subject=e.subject,
                text=e.body,
                html=html,
                cc=e.cc,
                bcc=e.bcc,
                attachments=list(self._process_attachments(e)),
            )
            if 'error' not in r:
                num_sent += 1
        return num_sent