Send one or more EmailMessage objects and return the number of email messages sent.
(self, email_messages)
| 163 | self.connection = None |
| 164 | |
| 165 | def send_messages(self, email_messages): |
| 166 | """ |
| 167 | Send one or more EmailMessage objects and return the number of email |
| 168 | messages sent. |
| 169 | """ |
| 170 | if not email_messages: |
| 171 | return 0 |
| 172 | with self._lock: |
| 173 | new_conn_created = self.open() |
| 174 | if not self.connection or new_conn_created is None: |
| 175 | # We failed silently on open(). |
| 176 | # Trying to send would be pointless. |
| 177 | return 0 |
| 178 | num_sent = 0 |
| 179 | try: |
| 180 | for message in email_messages: |
| 181 | sent = self._send(message) |
| 182 | if sent: |
| 183 | num_sent += 1 |
| 184 | finally: |
| 185 | if new_conn_created: |
| 186 | self.close() |
| 187 | return num_sent |
| 188 | |
| 189 | def _send(self, email_message): |
| 190 | """A helper method that does the actual sending.""" |
no test coverage detected