send email with token

This commit is contained in:
Frédéric Péters 2005-05-20 14:51:38 +00:00
parent b8b3e8d001
commit 0cb716779e
2 changed files with 9 additions and 35 deletions

View File

@ -10,6 +10,7 @@ from quixote.util import dump_request
from menu import html_top, html_foot
import wcs.emails
import wcs.misc
from wcs.users import User
from wcs import storage
@ -140,10 +141,14 @@ class UserPage(Directory):
form.render()
html_foot()
else:
pass # send by email
site_url = "%s://%s" % (request.get_scheme(), request.get_server())
body = _("""You have been given an identification token.
Log on %s to use it.
Your token is %s""") % (site_url, self.user.identification_token)
wcs.emails.email(_('Identification Token'), body, self.user.email)
return redirect('..')
class UsersDirectory(Directory):

View File

@ -1,13 +1,4 @@
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
from email.Header import Header
import smtplib
try:
import docutils
import docutils.core
except ImportError:
docutils = None
import emails
from quixote import get_request
@ -88,26 +79,4 @@ class FormDef(storage.Storable):
A new form has been submitted on the website, you can consult it with this
link: %(url)s
""") % {'url': url}
try:
htmlmail = docutils.core.publish_string(mail_body, writer_name="html")
except IOError:
htmlmail = None
msg = MIMEMultipart(_charset = 'iso-8859-15', _subtype = 'alternative')
msg['Subject'] = Header(_("A new form has been submitted"), 'iso-8859-15')
msg['To'] = self.emailrcpt
msg['From'] = 'WCS <noreply@entrouvert.com>'
msg['X-Mailer'] = 'w.c.s.'
msg.preamble = ''
msg.epilogue = ''
msg.attach(MIMEText(mail_body, _charset = 'iso-8859-15'))
if htmlmail:
msg.attach(MIMEText(htmlmail, _subtype = 'html'))
s = smtplib.SMTP()
s.connect()
s.sendmail('noreply@entrouvert.com', [msg['To']], msg.as_string())
s.close()
emails.email(_("A new form has been submitted"), mail_body, self.emailrcpt)