def send(self, subject, body, *, recipient): resp = self._client.send_email( Source=self._sender, Destination={"ToAddresses": [recipient]}, Message={ "Subject": { "Data": subject, "Charset": "UTF-8" }, "Body": { "Text": { "Data": body, "Charset": "UTF-8" } }, }, ) self._db.add( EmailMessage( message_id=resp["MessageId"], from_=parseaddr(self._sender)[1], to=parseaddr(recipient)[1], subject=subject, ))
def send(self, subject, body, *, recipient): message = MIMEMultipart("mixed") message["Subject"] = subject message["From"] = self._sender # The following is necessary to support friendly names with Unicode characters, # otherwise the entire value will get encoded and will not be accepted by SES: # # >>> parseaddr("Fööbar <*****@*****.**>") # ('Fööbar', '*****@*****.**') # >>> formataddr(_) # '=?utf-8?b?RsO2w7ZiYXI=?= <*****@*****.**>' message["To"] = formataddr(parseaddr(recipient)) message.attach(MIMEText(body, "plain", "utf-8")) resp = self._client.send_raw_email( Source=self._sender, Destinations=[recipient], RawMessage={"Data": message.as_string()}, ) self._db.add( EmailMessage( message_id=resp["MessageId"], from_=parseaddr(self._sender)[1], to=parseaddr(recipient)[1], subject=subject, ))
def test_starts_out_accepted(self, db_session): em = EmailStatus(EmailMessage()).save() assert em.status is EmailStatuses.Accepted