-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow empty from_email param #131
Open
tuliolages
wants to merge
8
commits into
develop
Choose a base branch
from
feat/allow-empty-from_email-param
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0e8826a
allows send_templated_mail from_email to be None
tuliolages ab7e45b
Allows from_email to be null and fallback to the DEFAULT_FROM_EMAIL s…
tuliolages 81a42e3
Removes unnecessary empty context param in send_mail and get_email_me…
tuliolages 4a27619
Update travis badge link to point to the new travis domain
tuliolages 158559e
Merge branch 'feat/update-travis-badge' into feat/allow-empty-from_em…
tuliolages 5f8a213
Add tests to class-based view from_email fallbacks
tuliolages 84e78da
Update README to better explain templated_email_from_email fallback
tuliolages 70692db
Updates the default mail backend to also try to use TEMPLATED_EMAIL_F…
tuliolages File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,7 +137,7 @@ def test_email_text_escaping(self): | |
) | ||
def test_get_email_message(self, mock): | ||
message = self.backend.get_email_message( | ||
'foo.email', {}, | ||
'foo.email', | ||
from_email='[email protected]', cc=['[email protected]'], | ||
bcc=['[email protected]'], to=['[email protected]']) | ||
self.assertTrue(isinstance(message, EmailMessage)) | ||
|
@@ -155,7 +155,7 @@ def test_get_email_message(self, mock): | |
) | ||
def test_get_email_message_with_create_link(self, mocked): | ||
self.backend.get_email_message( | ||
'foo.email', {}, | ||
'foo.email', | ||
from_email='[email protected]', cc=['[email protected]'], | ||
bcc=['[email protected]'], to=['[email protected]'], | ||
create_link=True) | ||
|
@@ -192,7 +192,7 @@ def test_get_email_message_with_inline_image(self, mocked): | |
) | ||
def test_custom_emailmessage_klass(self, mock): | ||
message = self.backend.get_email_message( | ||
'foo.email', {}, | ||
'foo.email', | ||
from_email='[email protected]', cc=['[email protected]'], | ||
bcc=['[email protected]'], to=['[email protected]']) | ||
self.assertTrue(isinstance(message, AnymailMessage)) | ||
|
@@ -205,7 +205,7 @@ def test_custom_emailmessage_klass(self, mock): | |
) | ||
def test_get_email_message_without_subject(self, mock): | ||
message = self.backend.get_email_message( | ||
'foo.email', {}, | ||
'foo.email', | ||
from_email='[email protected]', cc=['[email protected]'], | ||
bcc=['[email protected]'], to=['[email protected]']) | ||
self.assertTrue(isinstance(message, EmailMessage)) | ||
|
@@ -216,6 +216,55 @@ def test_get_email_message_without_subject(self, mock): | |
self.assertEqual(message.bcc, ['[email protected]']) | ||
self.assertEqual(message.from_email, '[email protected]') | ||
|
||
@patch.object( | ||
template_backend_klass, '_render_email', | ||
return_value={'plain': PLAIN_RESULT, 'subject': SUBJECT_RESULT} | ||
) | ||
def test_get_email_message_without_from_email_when_no_default_email_is_set(self, mock): | ||
message = self.backend.get_email_message( | ||
'foo.email', cc=['[email protected]'], | ||
bcc=['[email protected]'], to=['[email protected]']) | ||
self.assertTrue(isinstance(message, EmailMessage)) | ||
self.assertEqual(message.body, PLAIN_RESULT) | ||
self.assertEqual(message.subject, SUBJECT_RESULT) | ||
self.assertEqual(message.to, ['[email protected]']) | ||
self.assertEqual(message.cc, ['[email protected]']) | ||
self.assertEqual(message.bcc, ['[email protected]']) | ||
self.assertEqual(message.from_email, 'webmaster@localhost') | ||
|
||
@override_settings(DEFAULT_FROM_EMAIL='default.email@localhost') | ||
@patch.object( | ||
template_backend_klass, '_render_email', | ||
return_value={'plain': PLAIN_RESULT, 'subject': SUBJECT_RESULT} | ||
) | ||
def test_get_email_message_without_from_email_when_default_email_is_set(self, mock): | ||
message = self.backend.get_email_message( | ||
'foo.email', cc=['[email protected]'], | ||
bcc=['[email protected]'], to=['[email protected]']) | ||
self.assertTrue(isinstance(message, EmailMessage)) | ||
self.assertEqual(message.body, PLAIN_RESULT) | ||
self.assertEqual(message.subject, SUBJECT_RESULT) | ||
self.assertEqual(message.to, ['[email protected]']) | ||
self.assertEqual(message.cc, ['[email protected]']) | ||
self.assertEqual(message.bcc, ['[email protected]']) | ||
self.assertEqual(message.from_email, 'default.email@localhost') | ||
|
||
@patch.object( | ||
template_backend_klass, '_render_email', | ||
return_value={'plain': PLAIN_RESULT, 'subject': SUBJECT_RESULT} | ||
) | ||
def test_get_email_message_without_recipient_list(self, mock): | ||
message = self.backend.get_email_message( | ||
'foo.email', | ||
from_email='[email protected]') | ||
self.assertTrue(isinstance(message, EmailMessage)) | ||
self.assertEqual(message.body, PLAIN_RESULT) | ||
self.assertEqual(message.subject, SUBJECT_RESULT) | ||
self.assertEqual(message.to, []) | ||
self.assertEqual(message.cc, []) | ||
self.assertEqual(message.bcc, []) | ||
self.assertEqual(message.from_email, '[email protected]') | ||
|
||
@override_settings(TEMPLATED_EMAIL_DJANGO_SUBJECTS={'foo.email': | ||
'foo\r\n'}) | ||
@patch.object( | ||
|
@@ -224,7 +273,7 @@ def test_get_email_message_without_subject(self, mock): | |
) | ||
def test_get_email_message_without_subject_multiple_templates(self, mock): | ||
message = self.backend.get_email_message( | ||
['woo.email', 'foo.email'], {}, | ||
['woo.email', 'foo.email'], | ||
from_email='[email protected]', cc=['[email protected]'], | ||
bcc=['[email protected]'], to=['[email protected]']) | ||
self.assertTrue(isinstance(message, EmailMessage)) | ||
|
@@ -241,7 +290,7 @@ def test_get_email_message_without_subject_multiple_templates(self, mock): | |
) | ||
def test_get_email_message_generated_plain_text(self, mock): | ||
message = self.backend.get_email_message( | ||
'foo.email', {}, | ||
'foo.email', | ||
from_email='[email protected]', cc=['[email protected]'], | ||
bcc=['[email protected]'], to=['[email protected]']) | ||
self.assertTrue(isinstance(message, EmailMultiAlternatives)) | ||
|
@@ -260,12 +309,12 @@ def test_get_email_message_generated_plain_text(self, mock): | |
) | ||
@override_settings(TEMPLATED_EMAIL_PLAIN_FUNCTION=lambda x: 'hi') | ||
def test_get_email_message_custom_func_generated_plain_text(self, mock): | ||
message = self.backend.get_email_message('foo.email', {}) | ||
message = self.backend.get_email_message('foo.email') | ||
self.assertEqual(message.body, 'hi') | ||
|
||
def test_get_multi_match_last_email_message_generated_plain_text(self): | ||
message = self.backend.get_email_message( | ||
['multi-template.email', 'foo.email', ], {}, | ||
['multi-template.email', 'foo.email', ], | ||
from_email='[email protected]', cc=['[email protected]'], | ||
bcc=['[email protected]'], to=['[email protected]']) | ||
self.assertEqual(message.body, MULTI_TEMPLATE_PLAIN_RESULT) | ||
|
@@ -277,7 +326,7 @@ def test_get_multi_match_last_email_message_generated_plain_text(self): | |
|
||
def test_get_multi_first_match_email_message_generated_plain_text(self): | ||
message = self.backend.get_email_message( | ||
['foo.email', 'multi-template.email', ], {}, | ||
['foo.email', 'multi-template.email', ], | ||
from_email='[email protected]', cc=['[email protected]'], | ||
bcc=['[email protected]'], to=['[email protected]']) | ||
self.assertEqual(message.body, MULTI_TEMPLATE_PLAIN_RESULT) | ||
|
@@ -289,7 +338,7 @@ def test_get_multi_first_match_email_message_generated_plain_text(self): | |
|
||
def test_get_multi_options_select_last_plain_only(self): | ||
message = self.backend.get_email_message( | ||
['non-existing.email', 'also-non-existing.email', 'non-existing-without-suffix', 'foo.email', 'multi-template.email', ], {}, | ||
['non-existing.email', 'also-non-existing.email', 'non-existing-without-suffix', 'foo.email', 'multi-template.email', ], | ||
from_email='[email protected]', cc=['[email protected]'], | ||
bcc=['[email protected]'], to=['[email protected]']) | ||
self.assertEqual(message.body, MULTI_TEMPLATE_PLAIN_RESULT) | ||
|
@@ -306,7 +355,7 @@ def test_get_multi_options_select_last_plain_only(self): | |
) | ||
def test_get_email_message_with_plain_and_html(self, mock): | ||
message = self.backend.get_email_message( | ||
'foo.email', {}, | ||
'foo.email', | ||
from_email='[email protected]', cc=['[email protected]'], | ||
bcc=['[email protected]'], to=['[email protected]']) | ||
self.assertTrue(isinstance(message, EmailMultiAlternatives)) | ||
|
@@ -326,7 +375,7 @@ def test_get_email_message_with_plain_and_html(self, mock): | |
def test_get_email_message_with_no_body_parts(self, mock): | ||
with pytest.raises(EmailRenderException): | ||
self.backend.get_email_message( | ||
'foo.email', {}, | ||
'foo.email', | ||
from_email='[email protected]', cc=['[email protected]'], | ||
bcc=['[email protected]'], to=['[email protected]']) | ||
|
||
|
@@ -338,7 +387,7 @@ def test_get_email_message_with_no_body_parts(self, mock): | |
) | ||
def test_custom_emailmessage_klass_multipart(self, mock): | ||
message = self.backend.get_email_message( | ||
'foo.email', {}, | ||
'foo.email', | ||
from_email='[email protected]', cc=['[email protected]'], | ||
bcc=['[email protected]'], to=['[email protected]']) | ||
self.assertTrue(isinstance(message, AnymailMessage)) | ||
|
@@ -351,7 +400,7 @@ def test_custom_emailmessage_klass_multipart(self, mock): | |
) | ||
def test_get_email_message_html_only(self, mock): | ||
message = self.backend.get_email_message( | ||
'foo.email', {}, | ||
'foo.email', | ||
from_email='[email protected]', cc=['[email protected]'], | ||
bcc=['[email protected]'], to=['[email protected]']) | ||
self.assertTrue(isinstance(message, EmailMessage)) | ||
|
@@ -370,7 +419,7 @@ def test_get_email_message_html_only(self, mock): | |
) | ||
def test_send(self, render_mock): | ||
ret = self.backend.send('mixed_template', '[email protected]', | ||
['[email protected]', '[email protected]'], {}, | ||
['[email protected]', '[email protected]'], | ||
headers={'Message-Id': 'a_message_id'}) | ||
self.assertEqual(ret, 'a_message_id') | ||
self.assertEqual(len(mail.outbox), 1) | ||
|
@@ -443,7 +492,7 @@ def test_all_arguments_passed_forward_from_send( | |
) | ||
def test_send_attachment_mime_base(self, render_mock): | ||
self.backend.send('plain_template', '[email protected]', | ||
['[email protected]', '[email protected]'], {}, | ||
['[email protected]', '[email protected]'], | ||
attachments=[MIMEImage(TXT_FILE, 'text/plain')]) | ||
attachment = mail.outbox[0].attachments[0] | ||
self.assertEqual(decode_b64_msg(attachment.get_payload()), | ||
|
@@ -456,7 +505,7 @@ def test_send_attachment_mime_base(self, render_mock): | |
) | ||
def test_send_attachment_tripple(self, render_mock): | ||
self.backend.send('plain_template', '[email protected]', | ||
['[email protected]', '[email protected]'], {}, | ||
['[email protected]', '[email protected]'], | ||
attachments=[('black_pixel.png', TXT_FILE, 'text/plain')]) | ||
attachment = mail.outbox[0].attachments[0] | ||
self.assertEqual(('black_pixel.png', TXT_FILE, 'text/plain'), | ||
|
@@ -468,7 +517,7 @@ def test_send_attachment_tripple(self, render_mock): | |
) | ||
def test_get_email_message_attachment_mime_base(self, mock): | ||
message = self.backend.get_email_message( | ||
'foo.email', {}, | ||
'foo.email', | ||
from_email='[email protected]', cc=['[email protected]'], | ||
bcc=['[email protected]'], to=['[email protected]'], | ||
attachments=[MIMEImage(TXT_FILE, 'text/plain')]) | ||
|
@@ -482,7 +531,7 @@ def test_get_email_message_attachment_mime_base(self, mock): | |
) | ||
def test_get_email_message_attachment_tripple(self, mock): | ||
message = self.backend.get_email_message( | ||
'foo.email', {}, | ||
'foo.email', | ||
from_email='[email protected]', cc=['[email protected]'], | ||
bcc=['[email protected]'], to=['[email protected]'], | ||
attachments=[('black_pixel.png', TXT_FILE, 'text/plain')]) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have also a
TEMPLATED_EMAIL_FROM_EMAIL
setting.A user thought this was a default. See: #97 (comment)
So I think this should read:
from_email = from_email or settings.TEMPLATED_EMAIL_FROM_EMAIL or settings.DEFAULT_FROM_EMAIL
Also, check again the README, see if this is well explained. And check where
TEMPLATED_EMAIL_FROM_EMAIL
is being used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I've seen, this
TEMPLATED_EMAIL_FROM_EMAIL
is used only by the Class-based mixin. It's documentation is written here. While it's not saying explicitly that the setting is not required, it does not specify that it'll fall back toDEFAULT_FROM_MAIL
. I think this could be updated.I'm not sure, however, if we should put it as a default in the vanilla-django file, since this class-based mixin is like a wrapper over the vanilla and the docs specific that this setting is used only by the class-based view approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should make the backend use this setting
TEMPLATED_EMAIL_FROM_EMAIL
. Sofrom_email = from_email or settings.TEMPLATED_EMAIL_FROM_EMAIL or settings.DEFAULT_FROM_EMAIL
seems fine for me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fjsj I've updated the vanilla backend and added a note about this behavior in the readme.