From b514d386c889b874a733d107ad28d49babb38630 Mon Sep 17 00:00:00 2001 From: Christoph Goehre Date: Sun, 15 Mar 2009 18:42:32 +0100 Subject: send upload information mails with utf-8 charset With the release of Lenny, all changelog file must be UTF-8[1], so we can encode upload emails also as utf-8. This avoid broken Uploaders/Maintainers information. [1] http://release.debian.org/lenny/goals.txt Closes: #505144 --- minidinstall/mail.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 minidinstall/mail.py (limited to 'minidinstall') diff --git a/minidinstall/mail.py b/minidinstall/mail.py new file mode 100644 index 0000000..d1c7c0a --- /dev/null +++ b/minidinstall/mail.py @@ -0,0 +1,43 @@ +# mail -*- mode: python; coding: utf-8 -*- + +"""Simple mail support for mini-dinstall.""" + +# Copyright © 2008 Stephan Sürken + +# This file is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +import smtplib +import email.mime.text + +import logging + +def send(smtp_server, smtp_from, smtp_to, body, subject="mini-dinstall mail notice"): + """Send email; on error, log and continue.""" + + logger = logging.getLogger("mini-dinstall") + + try: + # Create a mime body + mime_body = email.mime.text.MIMEText(body, 'plain', 'utf-8') + mime_body['Subject'] = subject + mime_body['From'] = smtp_from + mime_body['To'] = smtp_to + + # Send via SMTP server + smtp = smtplib.SMTP(smtp_server) + smtp.sendmail(smtp_from, [smtp_to], mime_body.as_string()) + logger.info("Mail sent to %s (%s)" % (smtp_to, subject)) + except Exception, e: + logger.exception("Error sending mail to %s ('%s') via %s: %s: %s", smtp_to, subject, smtp_server, type(e), e.args) -- cgit v1.2.3