# HG changeset patch # User Thomas Waldmann # Date 1364251203 -3600 # Node ID 23bf696cf2940a72f43dfa0d171a9e689ab83ebe # Parent 819c4121f9a09a50913ec508b8d14d563f7f21b8 add a sendmail action, which can be use to submit POST data by E-Mail diff -r 819c4121f9a0 -r 23bf696cf294 data/plugin/action/sendmail.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/plugin/action/sendmail.py Mon Mar 25 23:40:03 2013 +0100 @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +""" +MoinMoin - sendmail action + +Send an E-Mail to configured recipient(s). + +Configuration: + sendmail_recipients = [u'admin@example.org', ] # only config + sendmail_subject = u'MoinMoin Form submission' # also from values + sendmail_template = u'%(values_json)s' # also from values + +Form: +sendmail_subject and sendmail_template can also be given via form elements. + +Placeholders in the sendmail_template will be replaced with the respective +form values. Be careful: if you need a verbatim % (percent char), you have +to put %% into the template. + +There are some special placeholders: + %(values_json)s json dump of the values + %(user_name)s user name of the current user + %(user_email)s user E-Mail address of the current user + +@copyright: 2013 MoinMoin:ThomasWaldmann +@license: GNU GPL, see COPYING for details. +""" + +try: + import json +except ImportError: + import simplejson as json + +from werkzeug import MultiDict + +from MoinMoin.Page import Page +from MoinMoin.mail.sendmail import sendmail + + +def execute(pagename, request): + if request.method == 'POST': + values = MultiDict(request.values) # make a mutable copy + # note: we do NOT get the recipients from the values to avoid spam abuse + to = request.cfg.sendmail_recipients + subject = values.pop('sendmail_subject', request.cfg.sendmail_subject) + template = values.pop('sendmail_template', request.cfg.sendmail_template) + values.add('values_json', json.dumps(values, sort_keys=True, ensure_ascii=False, indent=4)) + values.add('user_name', request.user.name) + values.add('user_email', request.user.email) + text = template % values.to_dict() + ok, msg = sendmail(request, to, subject, text) + else: + ok, msg = False, 'Please use a POST request.' + thispage = Page(request, pagename) + request.theme.add_msg(msg, "info" if ok else "error") + thispage.send_page()