{"action":"created","comment":{"url":"https://api.github.com/repos/anymail/django-anymail/pulls/comments/170342244","pull_request_review_id":99022355,"id":170342244,"diff_hunk":"@@ -0,0 +1,200 @@\n+from .base_requests import AnymailRequestsBackend, RequestsPayload\n+from ..exceptions import AnymailRequestsAPIError\n+from ..message import AnymailRecipientStatus\n+from ..utils import get_anymail_setting, parse_address_list\n+\n+\n+class EmailBackend(AnymailRequestsBackend):\n+    \"\"\"\n+    SendinBlue v3 API Email Backend\n+    \"\"\"\n+\n+    esp_name = \"SendinBlue\"\n+\n+    def __init__(self, **kwargs):\n+        \"\"\"Init options from Django settings\"\"\"\n+        esp_name = self.esp_name\n+        self.api_key = get_anymail_setting(\n+            'api_key',\n+            esp_name=esp_name,\n+            kwargs=kwargs,\n+            allow_bare=True,\n+        )\n+        api_url = get_anymail_setting(\n+            'api_url',\n+            esp_name=esp_name,\n+            kwargs=kwargs,\n+            default=\"https://api.sendinblue.com/v3\",\n+        )\n+        if not api_url.endswith(\"/\"):\n+            api_url += \"/\"\n+        super(EmailBackend, self).__init__(api_url, **kwargs)\n+\n+    def build_message_payload(self, message, defaults):\n+        return SendinBluePayload(message, defaults, self)\n+\n+    def raise_for_status(self, response, payload, message):\n+        if response.status_code < 200 or response.status_code >= 300:\n+            raise AnymailRequestsAPIError(\n+                email_message=message,\n+                payload=payload,\n+                response=response,\n+                backend=self,\n+            )\n+\n+    def parse_recipient_status(self, response, payload, message):\n+        # SendinBlue doesn't give any detail on a success\n+        # https://developers.sendinblue.com/docs/responses\n+        parsed_response = self.deserialize_json_response(response, payload, message)\n+        try:\n+            message_id = parsed_response['messageId']\n+        except (KeyError, TypeError):\n+            raise AnymailRequestsAPIError(\"Invalid SendinBlue API response format\",\n+                                          email_message=message, payload=payload, response=response,\n+                                          backend=self)\n+\n+        status = AnymailRecipientStatus(message_id=message_id, status=\"queued\")\n+        return {recipient.addr_spec: status for recipient in payload.all_recipients}\n+\n+\n+class SendinBluePayload(RequestsPayload):\n+\n+    def __init__(self, message, defaults, backend, *args, **kwargs):\n+        self.all_recipients = []  # used for backend.parse_recipient_status\n+        self.template_id = None\n+\n+        http_headers = kwargs.pop('headers', {})\n+        http_headers['api-key'] = backend.api_key\n+        http_headers['Content-Type'] = 'application/json'\n+\n+        super(SendinBluePayload, self).__init__(message, defaults, backend, headers=http_headers, *args, **kwargs)\n+\n+    def get_api_endpoint(self):\n+        if self.template_id:\n+            return \"smtp/templates/%s/send\" % (self.template_id)\n+        else:\n+            return \"smtp/email\"\n+\n+    def init_payload(self):\n+        self.data = {  # becomes json\n+            'sender': list(),\n+            'headers': dict()\n+        }\n+\n+    def serialize_data(self):\n+        \"\"\"Performs any necessary serialization on self.data, and returns the result.\"\"\"\n+\n+        headers = self.data[\"headers\"]\n+        if \"Reply-To\" in headers:\n+            # Reply-To must be in its own param\n+            reply_to = headers.pop('Reply-To')\n+            self.set_reply_to(parse_address_list([reply_to]))\n+        if len(headers) > 0:\n+            self.data[\"headers\"] = dict(headers)  # flatten to normal dict for json serialization\n+        else:\n+            del self.data[\"headers\"]  # don't send empty headers\n+\n+        # SendinBlue use different argument's name if we use template functionality\n+        if self.template_id:\n+            data = self._transform_data_for_templated_email(self.data)\n+        else:\n+            data = self.data\n+\n+        return self.serialize_json(data)\n+\n+    def _transform_data_for_templated_email(self, data):\n+        \"\"\"\n+        Transform the default Payload's data (used for basic transactional email) to\n+        the data used by SendinBlue in case of a templated transactional email.\n+        :param data: The data we want to transform\n+        :return: The transformed data\n+        \"\"\"\n+        transformation = {\n+            'to': 'emailTo',\n+            'cc': 'emailCc',\n+            'bcc': 'emailBcc,'\n+        }\n+        for key in self.data.keys():\n+            if key in transformation.keys():\n+                new_key = transformation[key]\n+                self.data[new_key] = [email.get('email') for email in self.data.pop(key)]","path":"anymail/backends/sendinblue.py","position":null,"original_position":120,"commit_id":"58eea0ef31e1539cf83e18b6d1caf146dcdecee8","original_commit_id":"9d644db232a94f14889464436658c8a3e2dba09c","user":{"login":"RignonNoel","id":12053720,"avatar_url":"https://avatars3.githubusercontent.com/u/12053720?v=4","gravatar_id":"","url":"https://api.github.com/users/RignonNoel","html_url":"https://github.com/RignonNoel","followers_url":"https://api.github.com/users/RignonNoel/followers","following_url":"https://api.github.com/users/RignonNoel/following{/other_user}","gists_url":"https://api.github.com/users/RignonNoel/gists{/gist_id}","starred_url":"https://api.github.com/users/RignonNoel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RignonNoel/subscriptions","organizations_url":"https://api.github.com/users/RignonNoel/orgs","repos_url":"https://api.github.com/users/RignonNoel/repos","events_url":"https://api.github.com/users/RignonNoel/events{/privacy}","received_events_url":"https://api.github.com/users/RignonNoel/received_events","type":"User","site_admin":false},"body":"SendinBlue doesn't support `display_name` on templated email :unamused: ...\r\n\r\nhttps://developers.sendinblue.com/v3.0/reference#sendtemplate\r\n```\r\ncurl --request POST \\\r\n  --url https://api.sendinblue.com/v3/smtp/templates/templateId/send \\\r\n  --data '{\"emailTo\":[\"to1@example.com\",\"to2@example.com\"]}'\r\n```","created_at":"2018-02-23T19:18:59Z","updated_at":"2018-02-23T19:18:59Z","html_url":"https://github.com/anymail/django-anymail/pull/93#discussion_r170342244","pull_request_url":"https://api.github.com/repos/anymail/django-anymail/pulls/93","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/anymail/django-anymail/pulls/comments/170342244"},"html":{"href":"https://github.com/anymail/django-anymail/pull/93#discussion_r170342244"},"pull_request":{"href":"https://api.github.com/repos/anymail/django-anymail/pulls/93"}},"in_reply_to_id":170161624},"pull_request":{"url":"https://api.github.com/repos/anymail/django-anymail/pulls/93","id":169757638,"html_url":"https://github.com/anymail/django-anymail/pull/93","diff_url":"https://github.com/anymail/django-anymail/pull/93.diff","patch_url":"https://github.com/anymail/django-anymail/pull/93.patch","issue_url":"https://api.github.com/repos/anymail/django-anymail/issues/93","number":93,"state":"open","locked":false,"title":"[WIP] Feature integration sendinblue","user":{"login":"RignonNoel","id":12053720,"avatar_url":"https://avatars3.githubusercontent.com/u/12053720?v=4","gravatar_id":"","url":"https://api.github.com/users/RignonNoel","html_url":"https://github.com/RignonNoel","followers_url":"https://api.github.com/users/RignonNoel/followers","following_url":"https://api.github.com/users/RignonNoel/following{/other_user}","gists_url":"https://api.github.com/users/RignonNoel/gists{/gist_id}","starred_url":"https://api.github.com/users/RignonNoel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RignonNoel/subscriptions","organizations_url":"https://api.github.com/users/RignonNoel/orgs","repos_url":"https://api.github.com/users/RignonNoel/repos","events_url":"https://api.github.com/users/RignonNoel/events{/privacy}","received_events_url":"https://api.github.com/users/RignonNoel/received_events","type":"User","site_admin":false},"body":"| Q                                                      | R\r\n| ------------------------------------------ | -------------------------------------------\r\n| Type of contribution ?                      | Feature\r\n| Tickets (_issues_) concerned               | fixed #84\r\n\r\n---\r\n\r\nI've begin an integration of `SendinBlue` with the new API v3, i took the choice to directly call the API and to not use the official python client implementation as recommended by `django-anymail` documentation.\r\n\r\nPlease feel free to review my code, contribute or just help me with some tips or good idea.\r\n\r\nI will continue this work soon 👍 \r\n \r\n##### What have you changed ?\r\n-  [x] Link the issue to this PR\r\n-  [x] Add my name in `AUTHORS.txt`\r\n-  [x] Create the Backend and Payload classes\r\n-  [x] Add or modify the attached tests\r\n-  [x] Add or modify the attached documentation\r\n-  [x] Test with an account of the ESP (Thank for the great integration testing ❤️ )\r\n-  [x] Add templated transactional email support\r\n-  [x] Add tag support\r\n\r\n##### How did you change it ?\r\nI've based my work on [this awaiting PR for Mailjet](https://github.com/anymail/django-anymail/blob/da25eb03b64d28d0a4effcf4fe014cd86ac9a7fd/anymail/backends/mailjet.py) and the `Sendgrid` integration.\r\n\r\n##### References\r\n\r\n 1. [SendinBlue's general documentation for API v3](https://developers.sendinblue.com/docs/getting-started)\r\n 2. [SensinBlue's dynamic test for API v3](https://developers.sendinblue.com/v3.0/reference#sendtransacemail-1)\r\n 3. [SendinBlue's official client API v3](https://github.com/sendinblue/APIv3-python-library)","created_at":"2018-02-17T00:47:32Z","updated_at":"2018-02-23T19:18:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7090eb82e2e8cc4367455b229414367a44ed9db3","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/anymail/django-anymail/pulls/93/commits","review_comments_url":"https://api.github.com/repos/anymail/django-anymail/pulls/93/comments","review_comment_url":"https://api.github.com/repos/anymail/django-anymail/pulls/comments{/number}","comments_url":"https://api.github.com/repos/anymail/django-anymail/issues/93/comments","statuses_url":"https://api.github.com/repos/anymail/django-anymail/statuses/58eea0ef31e1539cf83e18b6d1caf146dcdecee8","head":{"label":"RignonNoel:feature-integration_sendinblue","ref":"feature-integration_sendinblue","sha":"58eea0ef31e1539cf83e18b6d1caf146dcdecee8","user":{"login":"RignonNoel","id":12053720,"avatar_url":"https://avatars3.githubusercontent.com/u/12053720?v=4","gravatar_id":"","url":"https://api.github.com/users/RignonNoel","html_url":"https://github.com/RignonNoel","followers_url":"https://api.github.com/users/RignonNoel/followers","following_url":"https://api.github.com/users/RignonNoel/following{/other_user}","gists_url":"https://api.github.com/users/RignonNoel/gists{/gist_id}","starred_url":"https://api.github.com/users/RignonNoel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RignonNoel/subscriptions","organizations_url":"https://api.github.com/users/RignonNoel/orgs","repos_url":"https://api.github.com/users/RignonNoel/repos","events_url":"https://api.github.com/users/RignonNoel/events{/privacy}","received_events_url":"https://api.github.com/users/RignonNoel/received_events","type":"User","site_admin":false},"repo":{"id":121328614,"name":"django-anymail","full_name":"RignonNoel/django-anymail","owner":{"login":"RignonNoel","id":12053720,"avatar_url":"https://avatars3.githubusercontent.com/u/12053720?v=4","gravatar_id":"","url":"https://api.github.com/users/RignonNoel","html_url":"https://github.com/RignonNoel","followers_url":"https://api.github.com/users/RignonNoel/followers","following_url":"https://api.github.com/users/RignonNoel/following{/other_user}","gists_url":"https://api.github.com/users/RignonNoel/gists{/gist_id}","starred_url":"https://api.github.com/users/RignonNoel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RignonNoel/subscriptions","organizations_url":"https://api.github.com/users/RignonNoel/orgs","repos_url":"https://api.github.com/users/RignonNoel/repos","events_url":"https://api.github.com/users/RignonNoel/events{/privacy}","received_events_url":"https://api.github.com/users/RignonNoel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/RignonNoel/django-anymail","description":"Django email backends and webhooks for Mailgun, Mailjet, Postmark, SendGrid, SparkPost and more","fork":true,"url":"https://api.github.com/repos/RignonNoel/django-anymail","forks_url":"https://api.github.com/repos/RignonNoel/django-anymail/forks","keys_url":"https://api.github.com/repos/RignonNoel/django-anymail/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RignonNoel/django-anymail/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RignonNoel/django-anymail/teams","hooks_url":"https://api.github.com/repos/RignonNoel/django-anymail/hooks","issue_events_url":"https://api.github.com/repos/RignonNoel/django-anymail/issues/events{/number}","events_url":"https://api.github.com/repos/RignonNoel/django-anymail/events","assignees_url":"https://api.github.com/repos/RignonNoel/django-anymail/assignees{/user}","branches_url":"https://api.github.com/repos/RignonNoel/django-anymail/branches{/branch}","tags_url":"https://api.github.com/repos/RignonNoel/django-anymail/tags","blobs_url":"https://api.github.com/repos/RignonNoel/django-anymail/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RignonNoel/django-anymail/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RignonNoel/django-anymail/git/refs{/sha}","trees_url":"https://api.github.com/repos/RignonNoel/django-anymail/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RignonNoel/django-anymail/statuses/{sha}","languages_url":"https://api.github.com/repos/RignonNoel/django-anymail/languages","stargazers_url":"https://api.github.com/repos/RignonNoel/django-anymail/stargazers","contributors_url":"https://api.github.com/repos/RignonNoel/django-anymail/contributors","subscribers_url":"https://api.github.com/repos/RignonNoel/django-anymail/subscribers","subscription_url":"https://api.github.com/repos/RignonNoel/django-anymail/subscription","commits_url":"https://api.github.com/repos/RignonNoel/django-anymail/commits{/sha}","git_commits_url":"https://api.github.com/repos/RignonNoel/django-anymail/git/commits{/sha}","comments_url":"https://api.github.com/repos/RignonNoel/django-anymail/comments{/number}","issue_comment_url":"https://api.github.com/repos/RignonNoel/django-anymail/issues/comments{/number}","contents_url":"https://api.github.com/repos/RignonNoel/django-anymail/contents/{+path}","compare_url":"https://api.github.com/repos/RignonNoel/django-anymail/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RignonNoel/django-anymail/merges","archive_url":"https://api.github.com/repos/RignonNoel/django-anymail/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RignonNoel/django-anymail/downloads","issues_url":"https://api.github.com/repos/RignonNoel/django-anymail/issues{/number}","pulls_url":"https://api.github.com/repos/RignonNoel/django-anymail/pulls{/number}","milestones_url":"https://api.github.com/repos/RignonNoel/django-anymail/milestones{/number}","notifications_url":"https://api.github.com/repos/RignonNoel/django-anymail/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RignonNoel/django-anymail/labels{/name}","releases_url":"https://api.github.com/repos/RignonNoel/django-anymail/releases{/id}","deployments_url":"https://api.github.com/repos/RignonNoel/django-anymail/deployments","created_at":"2018-02-13T02:21:23Z","updated_at":"2018-02-13T02:21:25Z","pushed_at":"2018-02-23T19:16:45Z","git_url":"git://github.com/RignonNoel/django-anymail.git","ssh_url":"git@github.com:RignonNoel/django-anymail.git","clone_url":"https://github.com/RignonNoel/django-anymail.git","svn_url":"https://github.com/RignonNoel/django-anymail","homepage":"https://anymail.readthedocs.io/","size":1210,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"anymail:master","ref":"master","sha":"fffd762f56c6e6a567950240c59494a614e1ed8f","user":{"login":"anymail","id":17517617,"avatar_url":"https://avatars1.githubusercontent.com/u/17517617?v=4","gravatar_id":"","url":"https://api.github.com/users/anymail","html_url":"https://github.com/anymail","followers_url":"https://api.github.com/users/anymail/followers","following_url":"https://api.github.com/users/anymail/following{/other_user}","gists_url":"https://api.github.com/users/anymail/gists{/gist_id}","starred_url":"https://api.github.com/users/anymail/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anymail/subscriptions","organizations_url":"https://api.github.com/users/anymail/orgs","repos_url":"https://api.github.com/users/anymail/repos","events_url":"https://api.github.com/users/anymail/events{/privacy}","received_events_url":"https://api.github.com/users/anymail/received_events","type":"Organization","site_admin":false},"repo":{"id":53549881,"name":"django-anymail","full_name":"anymail/django-anymail","owner":{"login":"anymail","id":17517617,"avatar_url":"https://avatars1.githubusercontent.com/u/17517617?v=4","gravatar_id":"","url":"https://api.github.com/users/anymail","html_url":"https://github.com/anymail","followers_url":"https://api.github.com/users/anymail/followers","following_url":"https://api.github.com/users/anymail/following{/other_user}","gists_url":"https://api.github.com/users/anymail/gists{/gist_id}","starred_url":"https://api.github.com/users/anymail/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/anymail/subscriptions","organizations_url":"https://api.github.com/users/anymail/orgs","repos_url":"https://api.github.com/users/anymail/repos","events_url":"https://api.github.com/users/anymail/events{/privacy}","received_events_url":"https://api.github.com/users/anymail/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/anymail/django-anymail","description":"Django email backends and webhooks for Mailgun, Mailjet, Postmark, SendGrid, SparkPost and more","fork":false,"url":"https://api.github.com/repos/anymail/django-anymail","forks_url":"https://api.github.com/repos/anymail/django-anymail/forks","keys_url":"https://api.github.com/repos/anymail/django-anymail/keys{/key_id}","collaborators_url":"https://api.github.com/repos/anymail/django-anymail/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/anymail/django-anymail/teams","hooks_url":"https://api.github.com/repos/anymail/django-anymail/hooks","issue_events_url":"https://api.github.com/repos/anymail/django-anymail/issues/events{/number}","events_url":"https://api.github.com/repos/anymail/django-anymail/events","assignees_url":"https://api.github.com/repos/anymail/django-anymail/assignees{/user}","branches_url":"https://api.github.com/repos/anymail/django-anymail/branches{/branch}","tags_url":"https://api.github.com/repos/anymail/django-anymail/tags","blobs_url":"https://api.github.com/repos/anymail/django-anymail/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/anymail/django-anymail/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/anymail/django-anymail/git/refs{/sha}","trees_url":"https://api.github.com/repos/anymail/django-anymail/git/trees{/sha}","statuses_url":"https://api.github.com/repos/anymail/django-anymail/statuses/{sha}","languages_url":"https://api.github.com/repos/anymail/django-anymail/languages","stargazers_url":"https://api.github.com/repos/anymail/django-anymail/stargazers","contributors_url":"https://api.github.com/repos/anymail/django-anymail/contributors","subscribers_url":"https://api.github.com/repos/anymail/django-anymail/subscribers","subscription_url":"https://api.github.com/repos/anymail/django-anymail/subscription","commits_url":"https://api.github.com/repos/anymail/django-anymail/commits{/sha}","git_commits_url":"https://api.github.com/repos/anymail/django-anymail/git/commits{/sha}","comments_url":"https://api.github.com/repos/anymail/django-anymail/comments{/number}","issue_comment_url":"https://api.github.com/repos/anymail/django-anymail/issues/comments{/number}","contents_url":"https://api.github.com/repos/anymail/django-anymail/contents/{+path}","compare_url":"https://api.github.com/repos/anymail/django-anymail/compare/{base}...{head}","merges_url":"https://api.github.com/repos/anymail/django-anymail/merges","archive_url":"https://api.github.com/repos/anymail/django-anymail/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/anymail/django-anymail/downloads","issues_url":"https://api.github.com/repos/anymail/django-anymail/issues{/number}","pulls_url":"https://api.github.com/repos/anymail/django-anymail/pulls{/number}","milestones_url":"https://api.github.com/repos/anymail/django-anymail/milestones{/number}","notifications_url":"https://api.github.com/repos/anymail/django-anymail/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/anymail/django-anymail/labels{/name}","releases_url":"https://api.github.com/repos/anymail/django-anymail/releases{/id}","deployments_url":"https://api.github.com/repos/anymail/django-anymail/deployments","created_at":"2016-03-10T02:55:09Z","updated_at":"2018-02-23T15:47:03Z","pushed_at":"2018-02-23T19:16:46Z","git_url":"git://github.com/anymail/django-anymail.git","ssh_url":"git@github.com:anymail/django-anymail.git","clone_url":"https://github.com/anymail/django-anymail.git","svn_url":"https://github.com/anymail/django-anymail","homepage":"https://anymail.readthedocs.io/","size":1196,"stargazers_count":530,"watchers_count":530,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":42,"mirror_url":null,"archived":false,"open_issues_count":9,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause"},"forks":42,"open_issues":9,"watchers":530,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/anymail/django-anymail/pulls/93"},"html":{"href":"https://github.com/anymail/django-anymail/pull/93"},"issue":{"href":"https://api.github.com/repos/anymail/django-anymail/issues/93"},"comments":{"href":"https://api.github.com/repos/anymail/django-anymail/issues/93/comments"},"review_comments":{"href":"https://api.github.com/repos/anymail/django-anymail/pulls/93/comments"},"review_comment":{"href":"https://api.github.com/repos/anymail/django-anymail/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/anymail/django-anymail/pulls/93/commits"},"statuses":{"href":"https://api.github.com/repos/anymail/django-anymail/statuses/58eea0ef31e1539cf83e18b6d1caf146dcdecee8"}},"author_association":"NONE"}}
{"actor":{"display_login":"RignonNoel"}}