Skip to content
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

Enabling an option to send html emails #22

Closed
Dethada opened this issue May 21, 2018 · 3 comments
Closed

Enabling an option to send html emails #22

Dethada opened this issue May 21, 2018 · 3 comments
Assignees

Comments

@Dethada
Copy link
Contributor

Dethada commented May 21, 2018

The current send_verification function only allows sending of plain text emails, would be nice to have and option in the settings to send html emails.

I believe sending of html emails can be done by email_msg.content_subtype = 'html'

def send_verification(user, params_signer, template_config, email=None):
if email is None:
email_field = get_user_setting('EMAIL_FIELD')
email = getattr(user, email_field)
body_template = get_template(template_config['body'])
subject_template = get_template(template_config['subject'])
from_email = registration_settings.VERIFICATION_FROM_EMAIL
reply_to_email = (registration_settings.VERIFICATION_REPLY_TO_EMAIL or
from_email)
ctx = {
'user': user,
'email': email,
'verification_url': params_signer.get_url(),
}
subject = subject_template.render(ctx).strip()
body = body_template.render(ctx)
email_msg = EmailMessage(
subject, body,
from_email, [email], reply_to=[reply_to_email],
)
email_msg.send()

@apragacz
Copy link
Owner

Interesting idea, I will try to tackle it this weekend.

@apragacz
Copy link
Owner

HTML emails are still undocumented, but you can see valid cases of configuration here:

>>> doctest_utils.equals(
... parse_template_config({
... 'subject': 'rest_registration/register/subject.txt',
... 'html_body': 'rest_registration/register/body.html',
... 'text_body': 'rest_registration/register/body.txt',
... }),
... EmailTemplateConfig(
... 'rest_registration/register/subject.txt',
... 'rest_registration/register/body.txt',
... 'rest_registration/register/body.html',
... identity))
OK
>>> doctest_utils.equals(
... parse_template_config({
... 'subject': 'rest_registration/register/subject.txt',
... 'html_body': 'rest_registration/register/body.html',
... }),
... EmailTemplateConfig(
... 'rest_registration/register/subject.txt',
... 'rest_registration/register/body.html',
... 'rest_registration/register/body.html',
... convert_html_to_text))
OK
>>> doctest_utils.equals(
... parse_template_config({
... 'subject': 'rest_registration/register/subject.txt',
... 'text_body': 'rest_registration/register/body.txt',
... }),
... EmailTemplateConfig(
... 'rest_registration/register/subject.txt',
... 'rest_registration/register/body.txt', None,
... identity))
OK
>>> doctest_utils.equals(
... parse_template_config({
... 'subject': 'rest_registration/register/subject.txt',
... 'body': 'rest_registration/register/body.txt',
... }),
... EmailTemplateConfig(
... 'rest_registration/register/subject.txt',
... 'rest_registration/register/body.txt', None,
... identity))
OK
>>> doctest_utils.equals(
... parse_template_config({
... 'subject': 'rest_registration/register/subject.txt',
... 'body': 'rest_registration/register/body.html',
... 'is_html': True,
... }),
... EmailTemplateConfig(
... 'rest_registration/register/subject.txt',
... 'rest_registration/register/body.html',
... 'rest_registration/register/body.html',
... convert_html_to_text))

There are unit-tests but to be sincere I didn't see how such sent e-mail looks in a real mail reader.

@lock
Copy link

lock bot commented Sep 24, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants