Skip to content

Instantly share code, notes, and snippets.

@zopyx
Created May 18, 2016 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zopyx/24d907b591fba6fcf64e4d428e04bfb3 to your computer and use it in GitHub Desktop.
Save zopyx/24d907b591fba6fcf64e4d428e04bfb3 to your computer and use it in GitHub Desktop.
Sehr geehrte/r {kunde_text},
Ihr Kundenkonto mit der Kennung {kennung} wurde in unserem Webportal gelöscht.
Damit wurden alle persönlichen Bestelldaten aus unserem System entfernt.
Vielen Dank, dass Sie unsere Dienste genutzt haben.
Sollten Sie noch Fragen zur Löschung Ihres Kundenkontos haben, wenden Sie sich
bitte an unsere Kundenbetreuung ....
{footer}
import os
import string
import pkg_resources
from email.utils import formataddr
from email.MIMEText import MIMEText
import plone.api
from zopyx.plone.persistentlogger.logger import PersistentLoggerAdapter
class Formatter(string.Formatter):
def format(self, fmt, *args, **kw):
field_names = [tp[1] for tp in self.parse(fmt)]
for name in field_names:
if not name in kw:
kw[str(name)] = u''
else:
if not isinstance(kw[str(name)], unicode):
kw[str(name)] = unicode(kw[str(name)], 'utf8')
return super(Formatter, self).format(fmt, *args, **kw)
def send_mail(sender, recipients, subject, template, params, cc=[], cc_admin=False, context=None):
if 'NO_MAIL' in os.environ:
return
footer_text = pkg_resources.resource_string(
'zchl.policy.templates', 'footer.txt')
params['footer'] = unicode(footer_text, 'utf-8')
formatter = Formatter()
email_text = pkg_resources.resource_string(
'zchl.policy.templates', template)
try:
email_text = unicode(email_text, 'utf-8')
except UnicodeError:
email_text = unicode(email_text, 'iso-8859-15')
email_text = formatter.format(email_text, **params)
msg = MIMEText(email_text.encode('utf-8'), _charset='utf8')
msg.set_charset('utf-8')
recipients = [r for r in recipients if r]
msg['To'] = ','.join(recipients)
if sender:
msg['From'] = sender
else:
portal = plone.api.portal.get()
msg['From'] = formataddr(
(portal.email_from_name, portal.email_from_address))
if cc_admin:
cc.append(portal.email_from_address)
if cc:
msg['CC'] = ','.join(cc)
msg['Subject'] = subject
if context:
PersistentLoggerAdapter(context).log(
u'Benachrichtigung "{}" an {} gesendet'.format(subject, recipients))
mh = plone.api.portal.get_tool('MailHost')
mh.send(msg.as_string(), immediate=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment