def send(self, request):
if (not self.last_email) or self.last_email + timedelta(hours=12) < now(): # TODO: TIMEDELTA mit config
old_lang = translation.get_language()
translation.activate(self.user.language)
link = reverse('poll_vote', args=(self.poll.url,)) # TODO: hier direkt das poll oder das Vote?
email_content = render_to_string('invitations/mail_invite.txt', {
'receiver': self.user.username,
'creator': self.creator.username,
'link': link
})
try:
send_mail("Invitation to vote on {}".format(self.poll.title), email_content, None, [self.user.email])
self.last_email = now()
self.save()
except SMTPRecipientsRefused:
translation.activate(old_lang)
messages.error(
request, _("The mail server had an error sending the notification to {}".format(self.user.username))
)
translation.activate(old_lang)
else:
messages.error(
request, _("You have send an Email for {} in the last 12 Hours".format(self.user.username))
)
评论列表
文章目录