Commit Graph

885 Commits

Author SHA1 Message Date
medmunds
e85c4a911f Fix typo in Mailgun integration test
(Was causing false failures in ~1/6 of live integration runs,
depending on what order Mailgun generated events.)
2018-04-11 12:57:49 -07:00
medmunds
d9ea741cba Release 2.1 2018-04-11 12:33:13 -07:00
medmunds
2185d25301 Add "Amazon SES" to setup.py package description 2018-04-11 11:50:45 -07:00
medmunds
5598c87e62 Backends: identify source of problem in AnymailInvalidAddress message
Include the name of the field with the the unparsable email address
in AnymailInvalidAddress error messages.

Should help tracking down problems like in #98.
2018-04-11 11:50:06 -07:00
medmunds
f0d744a796 Internal: remove unused, undocumented AnymailInboundEvent attrs
AnymailInternalEvent had some properties that were actually implemented
in AnymailInboundMessage. The event versions were never documented,
and never contained useful data (they were always set to None).
2018-04-11 10:52:48 -07:00
Mike Edmunds
ef69fa3bf7 Amazon SES support
Integrate Amazon SES.

Closes #54.
2018-04-11 10:35:23 -07:00
medmunds
d079a506a1 Tests: better recipient addresses for live integration tests
Some ESPs have special blacklist handling for mailinator.com;
switch to (deliverable, blackholed) anymail.info test addresses.
2018-04-06 15:28:55 -07:00
medmunds
0ded9f7529 Postmark: Use new RecordType field to identify event types
Simplify Postmark tracking webhook code by using new "RecordType"
field introduced with Postmark "modular webhooks". (Rather than
looking for fields that are probably only in certain events.)

Also issue configuration error on inbound url installed as tracking
webhook (and vice versa).
2018-04-06 15:03:36 -07:00
medmunds
26cb882636 Postmark: Update docs and tests for "modular webhooks"
Existing tracking webhook code works fine with updated event payloads.
(So older Anymail versions will work, unmodified, with new Postmark
webhooks.)

Also update older doc links into Postmark docs.

Closes #101
2018-04-06 14:31:03 -07:00
medmunds
05f11db4ce SparkPost: add SPARKPOST_API_URL setting to allow SparkPost EU, etc.
Closes #100
2018-04-06 12:58:58 -07:00
medmunds
64bb3b6098 Docs: freeze left column of ESP feature matrix
(Make the wide table a little more readable.)
2018-04-05 18:03:59 -07:00
medmunds
802a56c87d Inbound: fix 8bit Unicode parsing as escape sequences on Python 3
Work around Python 3 email parser change that can turn Unicode
characters into \u escape sequences when parsing a message (or
attachment) that uses "Content-Transfer-Encoding: 8bit".
2018-04-02 16:41:05 -07:00
medmunds
008aef237e Internal: move lengthy compatibility EmailParser into own file 2018-04-01 17:26:46 -07:00
medmunds
dbe48d48af Inbound: add parse_raw_mime_bytes and parse_raw_mime_file
Useful for cases where ESP could send raw 8bit message
(and its charset is something other than utf-8).

Also reworks earlier Python 2.7 workaround email.parser.Parser header
unfolding bugs to handle any text-like, file-like IO stream, without
trying to manipulate the entire message as a single string.
2018-04-01 17:26:27 -07:00
medmunds
3928f6ea5e Inbound: fix charset handling in .text, .html, .get_content_text()
Make `AnymailInboundMessage.text`, `.html` and `.get_content_text()`
usually do the right thing for non-UTF-8 messages/attachments. Fixes
an incorrect UnicodeDecodeError when receiving an (e.g.,) ISO-8859-1
encoded message, and improves handling for inbound messages that were
not properly encoded by the sender.

* Decode using the message's (or attachments's) declared charset
  by default (rather than always defaulting to 'utf-8'; you can
  still override with `get_content_text(charset=...)`
* Add `errors` param to `get_content_text()`, defaulting to 'replace'.
  Mis-encoded messages will now use the Unicode replacement character
  rather than raising errors. (Use `get_content_text(errors='strict')`
  for the previous behavior.)
2018-04-01 17:26:17 -07:00
medmunds
97fc869992 Tests: backport assertLogs from Python 3.4 2018-03-29 12:27:03 -07:00
medmunds
eab11ed53e Inbound: test parsing RFC2231 MIME header parameters
And decide not to work around a Python 3.3 bug accessing MIME headers
that have non-ASCII characters in params. The bug is fixed in the
Python 3.4 email package (and didn't exist in Python 2.7). Python 3.3
was only supported with Django 1.8.
2018-03-24 17:47:06 -07:00
medmunds
b72e0b0274 Internal: Hoist RequestsPayload.serialize_json to BasePayload
(Non-Requests payloads sometimes want to serialize json, too.)
2018-03-24 10:09:46 -07:00
medmunds
3d27e3fe6b Inbound: decode Unicode and other non-ASCII email headers on Python 2
In AnymailInboundMessage, work around Python 2 email.parser.Parser's
lack of handling for RFC2047-encoded email headers. (The Python 3 email
package already decodes these automatically.)

Improves inbound handling on Python 2 for all ESPs that provide raw
MIME email or raw headers with inbound events. (Mailgun, Mandrill,
SendGrid, SparkPost.)
2018-03-24 10:03:18 -07:00
medmunds
70094cf3bc Inbound: correctly parse long (folded) headers in raw MIME messages
Work around Python 2 email.parser.Parser bug handling RFC5322 folded
headers. Fixes problems where long headers in inbound mail (e.g.,
Subject) get truncated or have unexpected spaces.

This change also updates AnymailInboundMessage.parse_raw_mime to use
the improved "default" email.policy on Python 3 (rather than the
default "compat32" policy). This likely fixes several other parsing
bugs that will still affect code running on Python 2.

Improves inbound parsing for all ESPs that provide raw MIME email.
(Mailgun, Mandrill, SendGrid, SparkPost)
2018-03-23 19:00:42 -07:00
medmunds
0c3e3e9bad Docs: css tweaks
* Add vertical space between items in "open" lists
  (rtfd/sphinx_rtd_theme#590)
* Distinguish shell prompts in console examples,
  and omit them if the code is copied
* Add css and js extras directly from Sphinx conf.py
  (no need to override template)
2018-03-16 12:16:57 -07:00
medmunds
b06d684dd5 Use tox for running tests and building docs
* Set up tox for testing supported Django/Python combinations
* Also include tox env for checking and building docs
* Use tox-travis for Travis CI integration
* Add tests against Django master
* Document building docs and running tests with tox
2018-03-15 13:08:07 -07:00
medmunds
b32c3ccb38 Travis: only run on release branches
Avoid running Travis builds twice for PRs (once for the feature
branch and once for the PR).

(Also simplify Travis pip cache using newer directive.)
2018-03-15 13:08:07 -07:00
medmunds
3874525fd0 Tests: use deliverable recipient addresses for live integration tests
Using undeliverable @example.com recipient addresses leads some ESPs
to flag the Anymail test accounts. Switch all live integration tests
to mailinator.com recipients (unless they were already using the ESP's
own "test sink" addresses).
2018-03-13 09:13:26 -07:00
medmunds
70f5e3e84c Release 2.0 2018-03-08 14:59:18 -08:00
Mike Edmunds
d93a66326c SendinBlue: implement tracking webhooks
Completes #84
2018-03-08 13:47:46 -08:00
medmunds
4b28760a9a SendinBlue: cleanup integration tests, more docs
* Don't send *quite* so many emails during live integration tests.
  (Our test account is throttled to 40/hour.)
* Relax message_id check in integration tests. SendinBlue appears
  to use both @smtp-relay.mail.fr and @smtp-relay.sendinblue.com
  Message-IDs.
* Note requirement for HTML message body in docs.
2018-03-07 18:50:52 -08:00
medmunds
ae8484fd65 Docs: clean up "securing webhooks"
* "SSL" --> "https"
* "authorization" --> "authentication"
  (e.g., "HTTP basic authentication" -- except when referring
  specifically to the HTTP "Authorization" header used to send it)
* add a sidebar with more details on why it matters
2018-03-07 12:19:38 -08:00
medmunds
e3f986df8f SendinBlue: fix template from_email checking
And add some tests for template unsupported feature warnings,
recipients in non-template sends.
2018-03-01 18:14:02 -08:00
medmunds
1e7aacdcb4 SendinBlue: update docs, readme, setup, Travis config
* Flesh out SendinBlue docs, add a readme mention
* Stop trying to list all the supported ESPs in the project short
  description and similar headlines -- it was becoming unwieldy.
* Support `pip install django-anymail[sendinblue]`
  and use it in Travis tests (for consistency; SendinBlue
  doesn't require any extra packages)
2018-03-01 17:29:57 -08:00
medmunds
9478bf5958 [Breaking] Webhooks: disallow deprecated WEBHOOK_AUTHORIZATION setting
Drop support for the WEBHOOK_AUTHORIZATION setting deprecated in v1.4.
Only the WEBHOOK_SECRET replacement is allowed now.

Most Django management commands will now issue a system check error
if the old name is still used in settings.py
2018-03-01 14:11:15 -08:00
medmunds
deea8c5d5b Setup: add universal wheel; update metadata; clean up setup.py
* Follow current setup.py recommendations from the pypa sample project
  (utf-8 encoding on file reads, ensure files are read relative to
  own location)
* Add/update some missing classifiers and other metadata
* Read _version.py constants into an isolated dict (rather than
  the global setup.py context)
* Add setup.cfg specifying universal bdist_wheel
2018-03-01 13:14:05 -08:00
medmunds
06c7077e37 Fix: flag extra_headers["To"] as unsupported
Django's SMTP EmailBackend allows spoofing the To header by setting
`message.extra_headers["To"]`` different from `message.to`.

No current Anymail ESP supports this. Treat extra_headers["To"] as
an unsupported ESP feature, to flag attempts to use it.

Also document Anymail's special header handling that replicates
Django's SMTP EmailBackend behavior.
2018-02-27 13:43:58 -08:00
medmunds
07fbeac6bd Feature: Add envelope_sender
New EmailMessage attribute `envelope_sender` controls ESP's sender,
sending domain, or return path where supported:

* Mailgun: overrides SENDER_DOMAIN on individual message
  (domain portion only)
* Mailjet: becomes `Sender` API param
* Mandrill: becomes `return_path_domain` API param
  (domain portion only)
* SparkPost: becomes `return_path` API param
* Other ESPs: not believed to be supported

Also support undocumented Django SMTP backend behavior, where envelope
sender is given by `message.from_email` when
`message.extra_headers["From"]` is set. Fixes #91.
2018-02-26 18:42:19 -08:00
medmunds
bd9d92f5a0 Cleanup: centralize Reply-To header handling; case-insensitive headers
Django allows setting the reply address with either message.reply_to
or message.extra_headers["Reply-To"]. If both are supplied, the extra
headers version takes precedence. (See EmailMessage.message().)

Several Anymail backends had duplicate logic to handle conflicting
properties. Move that logic into the base Payload.

(Also prepares for common handling of extra_headers['From'], later.)

Related changes:

* Use CaseInsensitiveDict for processing extra_headers.
  This is potentially a breaking change, but any code that was trying
  to send multiple headers differing only in case was likely already
  broken. (Email header field names are case-insensitive, per RFC-822.)

* Handle CaseInsensitiveDict in RequestsPayload.serialize_json().
  (Several backends had duplicate code for handling this, too.)

* Fixes SparkPost backend, which had been incorrectly treating
  message.reply_to and message.extra_headers['Reply-To'] differently.
2018-02-26 12:25:57 -08:00
medmunds
ec0ee336a2 Cleanup: Avoid Python 3.7 deprecation warning on 'async' keyword
Fixes #92
2018-02-26 10:24:08 -08:00
Rignon Noël
dc2b4b4e7a Add SendinBlue backend
Add support for sending transactional email through SendinBlue. (Thanks to @RignonNoel.)

Partially implements #84. (Tracking webhooks will be a separate PR. SendinBlue doesn't support inbound handling.)
2018-02-26 09:46:10 -08:00
medmunds
fffd762f56 Release 1.4 2018-02-08 11:44:23 -08:00
medmunds
1a6086f2b5 Security: rename WEBHOOK_AUTHORIZATION --> WEBHOOK_SECRET
This fixes a low severity security issue affecting Anymail v0.2--v1.3.

Django error reporting includes the value of your Anymail
WEBHOOK_AUTHORIZATION setting. In a properly-configured deployment,
this should not be cause for concern. But if you have somehow exposed
your Django error reports (e.g., by mis-deploying with DEBUG=True or by
sending error reports through insecure channels), anyone who gains
access to those reports could discover your webhook shared secret. An
attacker could use this to post fabricated or malicious Anymail
tracking/inbound events to your app, if you are using those Anymail
features.

The fix renames Anymail's webhook shared secret setting so that
Django's error reporting mechanism will [sanitize][0] it.

If you are using Anymail's event tracking and/or inbound webhooks, you
should upgrade to this release and change "WEBHOOK_AUTHORIZATION" to
"WEBHOOK_SECRET" in the ANYMAIL section of your settings.py. You may
also want to [rotate the shared secret][1] value, particularly if you
have ever exposed your Django error reports to untrusted individuals.

If you are only using Anymail's EmailBackends for sending email and
have not set up Anymail's webhooks, this issue does not affect you.

The old WEBHOOK_AUTHORIZATION setting is still allowed in this release,
but will issue a system-check warning when running most Django
management commands. It will be removed completely in a near-future
release, as a breaking change.

Thanks to Charlie DeTar (@yourcelf) for responsibly reporting this
security issue through private channels.

[0]: https://docs.djangoproject.com/en/stable/ref/settings/#debug
[1]: https://anymail.readthedocs.io/en/1.4/tips/securing_webhooks/#use-a-shared-authorization-secret
2018-02-08 11:38:15 -08:00
medmunds
4d34a181b6 Add Django AppConfig 2018-02-07 12:47:06 -08:00
medmunds
3468b12cc0 Release 1.3 2018-02-02 11:51:25 -08:00
medmunds
db586ede1f Security: prevent timing attack on WEBHOOK_AUTHORIZATION secret
Anymail's webhook validation was vulnerable to a timing attack.
An attacker could have used this to recover your WEBHOOK_AUTHORIZATION
shared secret, potentially allowing them to post fabricated or malicious
email tracking events to your app.

There have not been any reports of attempted exploit in the wild. (The
vulnerability was discovered through code review.) Attempts would be
visible in http logs as a very large number of 400 responses on
Anymail's webhook urls, or in Python error monitoring as a very large
number of AnymailWebhookValidationFailure exceptions.

If you are using Anymail's webhooks, you should upgrade to this release.
In addition, you may want to rotate to a new WEBHOOK_AUTHORIZATION
secret ([docs](http://anymail.readthedocs.io/en/stable/tips/securing_webhooks/#use-a-shared-authorization-secret)),
particularly if your logs indicate attempted exploit.
2018-02-02 11:41:14 -08:00
Mike Edmunds
b57eb94f64 Add inbound mail handling
Add normalized event, signal, and webhooks for inbound mail.

Closes #43
Closes #86
2018-02-02 10:38:53 -08:00
medmunds
c924c9ec03 Add developer notes on supporting new ESPs
(This should eventually migrate to the docs.)
2018-02-01 16:53:22 -08:00
Charlie DeTar
771d4040df Un-hardcode message_id in test backend; add console backend
* Un-hardcode status message_id in test backend

For the test EmailBackend, get message ID's based on array position in
`mail.outbox`, so that tests can predict the message ID.


* Add a console backend for use in development

Adds an EmailBackend derived from both Anymail's test backend and
Django's console backend, to provide anymail statuses and signal
handling while printing messages to the console.  For use during
development on localhost.

Closes #87
2018-01-28 12:25:05 -08:00
medmunds
09def30868 Add timeout to all Requests calls
Use a default timeout of 30 seconds for all requests, and add a
REQUESTS_TIMEOUT Anymail setting to override.

(I'm making a judgement call that this is not a breaking change in the
real world, and not bumping the major version. Theoretically, it could
affect you if your network somehow takes >30s to connect to your ESP,
but eventually succeeds. If so, set REQUESTS_TIMEOUT to None to restore
the earlier behavior.)

Fixes #80.
2018-01-17 14:36:50 -08:00
medmunds
5fb46952c6 Tests: fix MockRequestsBackend.get_api_call_arg edge cases
get_api_call_arg had incorrectly returned None if a kwarg was passed
to the mocked function with a False-y value (e.g., [] or {})

get_api_call_json had only considered data param, ignoring json param
requests added a while back
2018-01-17 13:53:06 -08:00
medmunds
2bf492c2f4 Docs: Update intersphinx source urls
Python and Django have both moved their docs to https.
2018-01-17 13:10:49 -08:00
medmunds
e454864232 Travis: switch to released Django 2.0
And move Python 3.6 live integration tests from Django 1.11
to Django 2.0.
2017-12-02 11:37:51 -08:00
medmunds
7029298b93 Release 1.2 2017-11-02 14:08:18 -07:00