async def send_email(self, msg: PubSubMessage) -> None: email = EmailMessage(**msg.data) email_raw = Message( subject=email.subject, to=email.to, body=email.body, html=email.html, from_address=email.from_address or self.email.from_address, cc=email.cc, bcc=email.bcc, reply_to=email.reply_to, date=email.date, ) for attachment in email.attachments: email_raw.attach( Attachment( filename=attachment.filename, content_type=attachment.content_type, data=attachment.data, )) await self.email.send(email_raw)
def test_attach(): msg = Message() att = Attachment() atts = [Attachment() for i in range(3)] msg.attach(att) assert msg.attachments == [att] msg.attach(*atts) assert msg.attachments == [att] + atts