Skip to content

Instantly share code, notes, and snippets.

@dogancankilment
Last active April 10, 2016 17:55
Show Gist options
  • Save dogancankilment/4612a595113b2adc3d6ba97fc243586c to your computer and use it in GitHub Desktop.
Save dogancankilment/4612a595113b2adc3d6ba97fc243586c to your computer and use it in GitHub Desktop.
Sending email with django and using token generator
from django.core.mail import EmailMultiAlternatives
from django.template import Context
from django.template.loader import render_to_string
from django.http import HttpResponse
from django.utils.translation import ugettext as _
from .util_token_generator import activation_key_generator
def mail_sender(email, controll):
subject, from_email = 'hello',\
'your@mail.com'
if email:
to = email
hash_key_example = activation_key_generator(to)
transmitted_key = Context(
{'hash_key': hash_key_example})
# text_content = plaintext.render(d)
if controll == "comment_activation":
text_content = render_to_string('email/comment_content.html',
transmitted_key)
else:
text_content = render_to_string('email/email_content.html',
transmitted_key)
msg = EmailMultiAlternatives(subject,
text_content,
from_email,
[to])
msg.send()
return HttpResponse(_("mail has been sent"))
else:
return HttpResponse(_("who do you want to send mail"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment