コード例 #1
0
ファイル: services.py プロジェクト: anzhaozhong/warehouse
    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,
            ))
コード例 #2
0
ファイル: services.py プロジェクト: ztane/warehouse
    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,
            ))
コード例 #3
0
ファイル: test_models.py プロジェクト: tomdottom/warehouse
 def test_starts_out_accepted(self, db_session):
     em = EmailStatus(EmailMessage()).save()
     assert em.status is EmailStatuses.Accepted