Permalink
Browse files

changed back to mail.send

  • Loading branch information...
mdipierro committed Jul 2, 2017
1 parent 5afbf37 commit 9372cddbb3766e678b092fc16800a76e2f6b2414
Showing with 40 additions and 306 deletions.
  1. +23 −25 controllers/default.py
  2. +5 −74 models/db.py
  3. +12 −7 models/db_votes.py
  4. +0 −3 models/ignore_ping.py
  5. +0 −32 models/menu.py
  6. +0 −31 models/messages.py
  7. +0 −134 static/js/web2py-bootstrap3.js.bak2
View
@@ -80,20 +80,19 @@ def start_callback():
link_vote = URL('vote',args=(election.id,voter_uuid),scheme=SCHEME)
link_ballots = URL('ballots',args=election.id,scheme=SCHEME)
link_results = URL('results',args=election.id,scheme=SCHEME)
message = message_replace(election.vote_email,
body = message_replace(election.vote_email,
election_id = election.id,
owner_email = owner_email,
title=election.title,
link=link_vote,
link_ballots=link_ballots,
link_results=link_results)
subject = '%s [%s]' % (election.title, election.id)
emails.append((voter,email,subject,message))
emails.append((voter,email,subject,body))
db.commit()
sender = election.email_sender or mail.settings.sender
for voter, to, subject, message in emails:
if meta_send2(to=to,subject=subject,message=message,
sender=sender, reply_to=sender):
for voter, to, subject, body in emails:
if mail.send(to=to, subject=subject, message=body, sender=sender):
db(db.voter.id==voter).update(invited_on=request.now)
else:
failures.append(to)
@@ -119,17 +118,15 @@ def self_service():
link_vote = URL('vote',args=(election.id,voter_uuid),scheme=SCHEME)
link_ballots = URL('ballots',args=election.id,scheme=SCHEME)
link_results = URL('results',args=election.id,scheme=SCHEME)
message = message_replace(election.vote_email,
body = message_replace(election.vote_email,
election_id = election.id,
owner_email = owner_email,
title=election.title,
link=link_vote,
link_ballots=link_ballots,
link_results=link_results)
sender = election.email_sender or mail.settings.sender
if meta_send2(to=voter.email,subject=election.title,
message=message,
sender=sender, reply_to=sender):
if mail.send(to=voter.email, subject=election.title, message=body, sender=sender):
response.flash = T('Email sent')
else:
response.flash = T('Unable to send email')
@@ -160,21 +157,21 @@ def reminders_callback():
link = URL('vote',args=(election.id,voter_uuid),scheme=SCHEME)
link_ballots = URL('ballots',args=election.id,scheme=SCHEME)
link_results = URL('results',args=election.id,scheme=SCHEME)
message = message_replace(election.vote_email,
body = message_replace(election.vote_email,
election_id = election.id,
owner_email = owner_email,
title=election.title,
link=link,
link_ballots=link_ballots,
link_results=link_results)
subject = '%s [%s]' % (election.title, election.id)
emails.append((email,subject,message))
emails.append((email,subject,body))
form = SQLFORM.factory(*fields).process()
if form.accepted:
sender = election.email_sender or mail.settings.sender
for to, subject, message in emails:
if not meta_send2(to=to,subject=subject,message=message,
sender=sender, reply_to=sender):
for to, subject, body in emails:
if not mail.send(to=to, subject=subject, message=body, sender=sender):
failures.append(email)
if not failures:
session.flash = T('Emails sent successfully')
@@ -293,20 +290,21 @@ def ballots():
return dict(ballots=ballots,election=election, tampered=tampered)
# @auth.requires(auth.user and auth.user.is_manager)
def email_voter_and_managers(election,voter,ballot,message):
def email_voter_and_managers(election,voter,ballot,body):
import cStringIO
attachment = mail.Attachment(
filename=ballot.ballot_uuid+'.html',
payload=cStringIO.StringIO(ballot.ballot_content))
sender = election.email_sender or mail.settings.sender
ret = meta_send(to=voter.email,
ret = mail.send(to=voter.email,
subject='Receipt for %s' % election.title,
message=message,attachments=[attachment],
sender=sender, reply_to=sender)
meta_send(to=regex_email.findall(election.managers),
message=body,attachments=[attachment],
sender=sender)
mail.send(to=regex_email.findall(election.managers),
subject='Copy of Receipt for %s' % election.title,
message=message,attachments=[attachment],
sender=sender, reply_to=sender)
message=body,
attachments=[attachment],
sender=sender)
return ret
def check_closed(election):
@@ -336,12 +334,12 @@ def close_election():
for i in range(len(voters)):
voter, ballot = voters[i], ballots[i]
link = URL('ballot',args=ballot.ballot_uuid,scheme='http')
message = message_replace(election.not_voted_email,
body = message_replace(election.not_voted_email,
election_id=election.id,
owner_email = owner_email,
title=election.title,
signature=ballot.signature,link=link)
email_voter_and_managers(election,voter,ballot,message)
email_voter_and_managers(election,voter,ballot,body)
ballot.update_record(assigned=True)
compute_results(election)
zippath = os.path.join(request.folder,'static','zips')
@@ -431,11 +429,11 @@ def vote():
link = URL('ballot',args=(ballot.ballot_uuid,ballot.signature),
scheme='http')
message = message_replace(election.voted_email,link=link,
body = message_replace(election.voted_email,link=link,
election_id=election.id,
owner_email = election.created_by.email,
title=election.title,signature=signature)
emailed = email_voter_and_managers(election,voter,ballot,message)
emailed = email_voter_and_managers(election,voter,ballot,body)
session.flash = \
T('Your vote was recorded and we sent you an email') \
if emailed else \
View
@@ -1,71 +1,22 @@
# -*- coding: utf-8 -*-
#########################################################################
## This scaffolding model makes your app work on Google App Engine too
## File is released under public domain and you can use without limitations
#########################################################################
## if SSL/HTTPS is properly configured and you want all HTTP requests to
## be redirected to HTTPS, uncomment the line below:
# request.requires_https()
## app configuration made easy. Look inside private/appconfig.ini
from gluon.tools import Auth
from gluon.contrib.appconfig import AppConfig
## once in production, remove reload=True to gain full speed
myconf = AppConfig(reload=True)
DEVELOPMENT = myconf.take('app.development').lower()=='true'
AS_SERVICE = myconf.take('app.as_service').lower()=='true'
DEBUG_MODE = myconf.take('app.debug_mode').lower()=='true'
SCHEME = True if DEVELOPMENT else 'https'
if not request.env.web2py_runtime_gae:
## if NOT running on Google App Engine use SQLite or other DB
db = DAL(myconf.take('db.uri'), pool_size=myconf.take('db.pool_size', cast=int), check_reserved=['all'])
else:
## connect to Google BigTable (optional 'google:datastore://namespace')
db = DAL('google:datastore+ndb')
## store sessions and tickets there
session.connect(request, response, db=db)
## or store session in Memcache, Redis, etc.
## from gluon.contrib.memdb import MEMDB
## from google.appengine.api.memcache import Client
## session.connect(request, response, db = MEMDB(Client()))
db = DAL(myconf.take('db.uri'), pool_size=myconf.take('db.pool_size', cast=int), check_reserved=['all'])
## by default give a view/generic.extension to all actions from localhost
## none otherwise. a pattern can be 'controller/function.extension'
response.generic_patterns = ['*'] if request.is_local else []
## choose a style for forms
response.generic_patterns = []
response.formstyle = myconf.take('forms.formstyle') # or 'bootstrap3_stacked' or 'bootstrap2' or other
response.form_label_separator = myconf.take('forms.separator')
## (optional) optimize handling of static files
# response.optimize_css = 'concat,minify,inline'
# response.optimize_js = 'concat,minify,inline'
## (optional) static assets folder versioning
# response.static_version = '0.0.0'
#########################################################################
## Here is sample code if you need for
## - email capabilities
## - authentication (registration, login, logout, ... )
## - authorization (role based authorization)
## - services (xml, csv, json, xmlrpc, jsonrpc, amf, rss)
## - old style crud actions
## (more options discussed in gluon/tools.py)
#########################################################################
from gluon.tools import Auth, Service, PluginManager
auth = Auth(db)
service = Service()
plugins = PluginManager()
## create all tables needed by auth if not custom tables
maybe_can_choose = AS_SERVICE or DEVELOPMENT
auth.settings.extra_fields['auth_user'] = [
Field('is_manager','boolean',default=False,
writable=maybe_can_choose, readable=maybe_can_choose)]
auth.define_tables(username=False, signature=False)
## configure email
mail = auth.settings.mailer
@@ -77,23 +28,3 @@
auth.settings.registration_requires_verification = not DEVELOPMENT
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True
#########################################################################
## Define your tables below (or better in another model file) for example
##
## >>> db.define_table('mytable',Field('myfield','string'))
##
## Fields can be 'string','text','password','integer','double','boolean'
## 'date','time','datetime','blob','upload', 'reference TABLENAME'
## There is an implicit 'id integer autoincrement' field
## Consult manual for more options, validators, etc.
##
## More API examples for controllers:
##
## >>> db.mytable.insert(myfield='value')
## >>> rows=db(db.mytable.myfield=='value').select(db.mytable.ALL)
## >>> for row in rows: print row.id, row.myfield
#########################################################################
## after defining tables, uncomment below to enable auditing
# auth.enable_record_versioning(db)
View
@@ -1,11 +1,18 @@
not_empty = IS_NOT_EMPTY()
NE = IS_NOT_EMPTY()
maybe_can_choose = AS_SERVICE or DEVELOPMENT
auth.settings.extra_fields['auth_user'] = [
Field('is_manager','boolean',default=False, writable=maybe_can_choose, readable=maybe_can_choose)]
auth.define_tables(username=False, signature=False)
db.define_table(
'election',
Field('title',requires=not_empty),
Field('ballot_model','text',requires=not_empty), # empty ballot
Field('voters','text',requires=not_empty),
Field('managers','text',requires=not_empty),
Field('title',requires=NE),
Field('ballot_model','text',requires=NE), # empty ballot
Field('voters','text',requires=NE),
Field('managers','text',requires=NE),
Field('deadline','datetime'),
Field('vote_email','text'),
Field('voted_email','text'),
@@ -36,5 +43,3 @@
Field('results','json',default={}),
Field('ballot_uuid'), # uuid embedded in ballot
Field('signature')) # signature of ballot (voted or blank)
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View
@@ -68,34 +68,3 @@ def message_replace(message,**vars):
for key in vars:
message = message.replace('{{=%s}}' % key, str(vars[key]))
return message
def meta_send(*args, **kwargs):
if kwargs.get('sender') == myconf.take('smtp.sender'):
mail.settings.server = myconf.take('smtp.server')
mail.settings.login = myconf.take('smtp.login')
return mail.send(*args, **kwargs)
def meta_send2(to,message,reply_to,subject,sender=None):
import smtplib
fromaddr = mail.settings.sender
msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\nReply-to: %s\r\n\r\n%s" \
% (fromaddr, to, subject, reply_to, message)
if mail.settings.server=='logging':
print msg
return True
try:
server = None
server = smtplib.SMTP(mail.settings.server,timeout=5)
server.ehlo(mail.settings.hostname)
server.starttls()
server.ehlo(mail.settings.hostname)
if mail.settings.login:
server.login(*mail.settings.login.split(':', 1))
server.sendmail(fromaddr, [to], msg)
return True
except:
return False
finally:
if server:
server.quit()
Oops, something went wrong.

0 comments on commit 9372cdd

Please sign in to comment.