Commit Graph

65 Commits

Author SHA1 Message Date
medmunds
d0596d100b Raise error for invalidly-formatted email addresses.
A message's `from_email` and each address in its `to`, `cc`, and `bcc` lists must contain exactly one email address. Previous code would silently ignore additional addresses, leading to unusual behavior. Now, raises new `AnymailInvalidAddress` exception.

Example: `from_email='Widgets, Inc. <widgets@example.com>'` is invalid: it needs double-quotes around the "Widgets, Inc." display-name portion. In earlier versions, this probably would have sent the message from something like "From: Widgets <@localhost>". Now, it will raise an exception.

**Potentially-breaking change:** If your code is using an unquoted display-name containing a comma in an email address, it will now raise an error. In earlier versions, this may have appeared to succeed, but was almost certainly not doing what you intended.

Fixes #44.
2016-12-15 13:57:49 -08:00
medmunds
4ca39a976f Postmark: handle Reply-To in EmailMessage headers
Move 'Reply-To' header into dedicated Postmark API param

Fixes #39
2016-11-01 12:12:21 -07:00
Seb Bacon
f0589e3338 Compatibility with earlier Python 2.7 versions
Compatibility with Python 2.7 versions older than 2.7.7

* Use Django's constant_time_compare method
* Include sparkpost in test requirements
* Don't use non-public `EnvironmentVarGuard` in tests

Fixes #41
2016-11-01 11:24:51 -07:00
medmunds
d54d7ecff5 Open development for v0.7
[ci skip]
2016-10-25 11:53:41 -07:00
medmunds
5ea93ce2db Release 0.6 2016-10-25 11:28:29 -07:00
medmunds
7248c3441e Postmark: add track_clicks support
Closes #38
2016-10-23 10:54:59 -07:00
medmunds
60dc11559d AnymailMessage: initialize anymail_status to empty AnymailStatus
Allows clients that use AnymailMessage or AnymailMessageMixin
to access (e.g.) message.anymail_status.message_id without
an AttributeError, even when using a non-Anymail backend
(e.g., during testing).

Also clarify docs of anymail_status attribute to note it only gets
attached to a normal Django EmailMessage when sent through
an Anymail backend.

(May help with situation described in #36)
2016-10-20 11:50:31 -07:00
medmunds
a1380b82f3 SendGrid: force empty text and html to " " with template_id
Work around an unexpected limitation in SendGrid template
rendering, where template text or html bodies are omitted
if the supplied message text or html is "". Changing empty
string to " " works around the issue.

https://sendgrid.com/docs/API_Reference/Web_API_v3/Transactional_Templates/smtpapi.html#-Text-or-HTML-Templates

Closes #32
2016-10-13 15:15:37 -07:00
medmunds
46f8328b28 Release 0.5 2016-08-22 10:56:22 -07:00
medmunds
fb21c0d25b Mailgun: Add MAILGUN_SENDER_DOMAIN setting
Allow custom MAILGUN_SENDER_DOMAIN in Anymail
settings. (Replaces need to use global esp_extra.)

Improve docs to cover cases where this is needed.

(esp_extra sender_domain is still supported for
overriding individual messages.)

Fixes #26.
2016-08-03 14:19:35 -07:00
medmunds
f95be248ec SparkPost: remove empty content params with template_id
When using a stored template, SparkPost disallows
subject, text, and html. Django's EmailMessage default
empty strings are enough to provoke "Both content
object and template_id are specified" from SparkPost,
so remove them (if empty) when using stored templates.

Update docs and tests; add integration test for template_id.

Fixes #24
2016-06-24 12:13:32 -07:00
medmunds
a4f43d17d2 Open 0.5 dev
[ci skip]
2016-06-22 17:48:41 -07:00
medmunds
54604ea23d Release 0.4.1 2016-06-22 17:42:06 -07:00
medmunds
b664ee3dbc SparkPost: work around json recipients problem
python-sparkpost generates a transmissions.send
payload which is now considered invalid by the API,
if you try to use both `cc` (or `bcc`) and the
`recipients` dict structure required for merge_data.

[Anymail had been generating that recipients dict
structure in all cases, for simplicity. Sometime
between 2016-06-07 and 2016-06-22, SparkPost
began rejecting that if it appeared in the `header_to`
constructed by python-sparkpost.]
2016-06-22 16:58:56 -07:00
medmunds
5adb07a1be Open version 0.4.1.dev
[ci skip]
2016-06-22 16:58:56 -07:00
medmunds
cf04a89426 Release 0.4 2016-06-22 15:39:47 -07:00
Mike Edmunds
db101bf6b9 Add SparkPost support (#20)
Implement SparkPost backend and tracking webhooks.

Closes #11.
2016-06-22 15:31:30 -07:00
medmunds
1ea9ab6fee Upgrade requests exceptions to AnymailRequestsAPIError
Catch and re-raise requests.RequestException in
AnymailRequestsBackend.post_to_esp.

* AnymailRequestsAPIError is needed for proper
  fail_silently handling.
* Retain original requests exception type, to avoid
  breaking existing code that might look for specific
  requests exceptions.

Closes #16
2016-06-01 10:18:27 -07:00
medmunds
5d417080ee SendGrid: set to to from in batch send.
Set ignored (but required-valid) `to` field to
the from_email for batch send with merge_data.
See https://github.com/anymail/django-anymail/pull/14#issuecomment-220231250
2016-06-01 08:05:51 -07:00
medmunds
af0e36ab65 Webhooks: fix 403 Forbidden errors (csrf check)
* csrf_exempt must be applied to View.dispatch,
  not View.post.

* In base WebhookTestCase, enable Django test Client
  enforce_csrf_checks. (Test Client by default disables
  CSRF protection.)

Closes #19
2016-05-31 11:57:48 -07:00
medmunds
995617a130 SendGrid: improve to handling with merge_data
* Add merge_data integration test
* Simplify backend handling for this case
  (also fixes duplicated to's in all_recipients
  from previous fix)
2016-05-18 11:23:01 -07:00
Lewis Taylor
72d899460c SendGrid: Set to field when using merge_data (#14)
* Set to field when using merge_data

The `to` field is required even if providing recipient addresses in x-smtpapi. See https://sendgrid.com/docs/API_Reference/Web_API/mail.html#-send.

* Check data['to'] contains expected emails

* Add space for toname check

* Make `to` expected data contain email only
2016-05-18 11:01:54 -07:00
medmunds
23becd35a9 Open 0.4 dev
[ci skip]
2016-05-13 12:27:37 -07:00
medmunds
772e1f47e0 Release 0.3 2016-05-13 12:20:05 -07:00
medmunds
f8eafba0df Add pre_send and post_send signals
Closes #8
2016-05-12 21:18:04 -07:00
medmunds
c60790fb52 Use generic TestBackend for base functionality tests
* Create generic TestBackend that simply collects
  send parameters
* Change BackendSettingsTests to TestBackend,
  and add some missing cases
* Add UnsupportedFeatureTests
* Replace repetitive per-backend SEND_DEFAULTS
  test cases with single (and more comprehensive)
  SendDefaultsTests
2016-05-12 17:18:48 -07:00
medmunds
a0b92bee7a Mandrill: support esp_extra
* Merge esp_extra with Mandrill send payload
* Handle pythonic forms of `recipient_metadata`
  and `template_content` in esp_extra
* DeprecationWarning for Mandrill EmailMessage
  attributes inherited from Djrill
2016-05-11 15:08:57 -07:00
medmunds
75730e8219 Add ESP templates, batch send and merge
* message.template_id to use ESP stored templates
* message.merge_data and merge_global_data
  to supply per-recipient/global merge variables
  (with or without an ESP stored template)
* When using per-recipient merge_data, tell ESP to use
  batch send: individual message per "to" address.
  (Mailgun does this automatically; SendGrid requires
  using a different "to" field; Mandrill requires
  `preserve_recipients=False`; Postmark doesn't
  support *this type* of batch sending with merge data.)
* Allow message.from_email=None (must be set after
  init) and message.subject=None to suppress those
  fields in API calls (for ESPs that allow "From" and
  "Subject" in their template definitions).

Mailgun:
* Emulate merge_global_data by copying to
  recipient-variables for each recipient.

SendGrid:
* Add delimiters to merge field names via
  esp_extra['merge_field_format'] or
  ANYMAIL_SENDGRID_MERGE_FIELD_FORMAT setting.

Mandrill:
* Remove Djrill versions of these features;
  update migration notes.

Closes #5.
2016-05-06 12:27:11 -07:00
medmunds
7b82b23156 Open development for 0.3
[ci skip]
2016-04-30 11:13:49 -07:00
medmunds
c2d0772cad Prep release 0.2 2016-04-30 10:34:16 -07:00
medmunds
c7a8c81e32 Remove pre-Django 1.8 compatibility code 2016-04-30 10:33:51 -07:00
medmunds
1372ef21eb SendGrid: merge 'filters' in esp_extra
Previously, setting esp_extra['x-smtpapi']['filters']
would override the entire filters setting, potentially
undoing other Anymail options that use SendGrid
filters (like track_opens).

Now, 'filters' is special-cased, and merged with
any other Anymail filter options.

(We don't do a fully deep merge, because otherwise
there would be no way to use esp_extra to *clear*
Anymail settings.)
2016-04-30 10:21:11 -07:00
medmunds
d3f914be12 Event-tracking webhooks
Closes #3
2016-04-29 18:10:50 -07:00
medmunds
36461e57b9 Keep angle brackets on SendGrid smtp-id
SendGrid seems to consistently use <angle brackets>
on Message-ID and smtp-id.
2016-04-29 15:05:58 -07:00
medmunds
df881fdb75 Allow kwargs overrides for (nearly) all settings
* Update utils.get_anymail_setting to support
  kwargs override of django.conf.settings values
* Use the updated version everywhere
* Switch from ImproperlyConfigured to
  AnymailConfigurationError exception
  (anticipates feature_wehooks change)

Closes #12
2016-04-29 14:34:34 -07:00
medmunds
ebe6710326 Get rid of magic JSON serialization for Mailgun metadata.
Treat Mailgun metadata like all other ESPs: simple
key-value dict, where values are strings. If you want
to store JSON in metadata, you should serialize and
deserialize it yourself.
2016-04-29 09:46:13 -07:00
medmunds
8e43f29944 Workaround missing smtp-id in SendGrid tracking.
* Add smtp-id in unique_args (metadata), to ensure
  it shows up in click and open events.
* Add SENDGRID_GENERATE_MESSAGE_ID setting,
  default True, to control auto-Message-ID behavior.
* Document it.
2016-04-29 09:44:31 -07:00
medmunds
385d76b53a Move tests out of app module
(Directory structure as suggested in
[Django testing docs][1].)

[1]: https://docs.djangoproject.com/en/1.9/topics/testing/advanced/#using-the-django-test-runner-to-test-reusable-applications
2016-03-21 11:38:58 -07:00
medmunds
abca7d9538 Clean up old Djrill/Mandrill tests
* Match other ESP test strategies for
  test_mandrill_backend and
  test_mandrill_integration

* Extract test_mandrill_session_sharing into
  SessionSharingTestCasesMixin for all
  requests-based ESP backends

* Move leftover Djrill feature tests into
  test_mandrill_djrill features (until they are
  handled as part of esp_extra or in normalized
  ESP template/merge features)

Closes #7
2016-03-15 18:08:41 -07:00
medmunds
2b1c7d0dce Open 0.2.dev0
[ci skip]
2016-03-14 19:47:04 -07:00
medmunds
1c474e5c40 release 0.1 2016-03-14 13:50:51 -07:00
medmunds
fed98b14a8 install: remove need to name [esp]
Simplify install to just `pip install django-anymail`.
(Rather than `... django-anymail[mailgun]`

All of the ESPs so far require requests, so just move
that into the base requirements. (Chances are your
Django app already needs requests for some other
reason, anyway.)

Truly unique ESP dependencies (e.g., boto for
AWS-SES) could still use the setup extra features
mechanism.
2016-03-14 13:26:06 -07:00
medmunds
7bbd1c7e4e SendGrid: support username/password auth
Closes #9
2016-03-14 12:39:41 -07:00
medmunds
34d6676afa Add Postmark support 2016-03-14 11:06:45 -07:00
medmunds
a8d4ca7c28 Bump version to 0.1.dev2 2016-03-11 19:15:17 -08:00
medmunds
54827579d3 Improve inline-image handling
* Add filename param to attach_inline_image

* Add attach_inline_image_file function
  (parallels EmailMessage.attach and attach_file)

* Use `Content-Disposition: inline` to decide
  whether an attachment should be handled inline
  (whether or not it's an image, and whether or not
  it has a Content-ID)

* Stop conflating filename and Content-ID, for
  ESPs that allow both. (Solves problem where
  Google Inbox was displaying inline images
  as attachments when sent through SendGrid.)
2016-03-11 19:14:11 -08:00
medmunds
701726c59d Fix SG integration tests 2016-03-11 16:28:46 -08:00
medmunds
e15cb46daf Implement SendGridBackend
Covers most of #1
2016-03-11 16:17:02 -08:00
medmunds
b407e9f452 Preserve filename of inline attachments
For ESPs that support both content-id and filename,
don't drop the filename.
2016-03-11 10:07:13 -08:00
medmunds
6214fbbdcd utils: add datetime-->timestamp conversion 2016-03-11 10:04:43 -08:00