From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id CE2C9139085 for ; Sat, 24 Dec 2016 09:13:56 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A71182340F2; Sat, 24 Dec 2016 09:13:35 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 86D3D2340F2 for ; Sat, 24 Dec 2016 09:13:35 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 3958B341236 for ; Sat, 24 Dec 2016 09:13:19 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 4E7BF24EF for ; Sat, 24 Dec 2016 09:13:16 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <1482555254.78c83d8030ad8628887e2705bdc95b485a8e42be.dolsen@gentoo> Subject: [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/ X-VCS-Repository: proj/gentoo-keys X-VCS-Files: gkeys/gkeys/mail.py X-VCS-Directories: gkeys/gkeys/ X-VCS-Committer: dolsen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 78c83d8030ad8628887e2705bdc95b485a8e42be X-VCS-Branch: gsoc-2016 Date: Sat, 24 Dec 2016 09:13:16 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: c7807441-437f-43c0-a6e9-d8f0a585d0fd X-Archives-Hash: 2e8bd998afd4a056e91be0a0861b8652 commit: 78c83d8030ad8628887e2705bdc95b485a8e42be Author: aeroniero33 gmail com> AuthorDate: Sat Aug 27 14:07:07 2016 +0000 Commit: Brian Dolbec gentoo org> CommitDate: Sat Dec 24 04:54:14 2016 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=78c83d80 Added a mail script that handles the emailing proccess I created a new file called `mail.py` that handles the email login and the email sending. gkeys/gkeys/mail.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/gkeys/gkeys/mail.py b/gkeys/gkeys/mail.py new file mode 100644 index 0000000..df86d11 --- /dev/null +++ b/gkeys/gkeys/mail.py @@ -0,0 +1,51 @@ +from __future__ import print_function + +import os +import smtplib +import sys +import email.utils + +from email.mime.text import MIMEText +from snakeoil.demandload import demandload + +if sys.version_info[0] >= 3: + py_input = input + _unicode = str +else: + py_input = raw_input + _unicode = unicode + +demandload( + "gkeys.base:Args", + "json:load", +) + +class Emailer(object): + '''Send an email reminder about the status of the user's GPG key''' + + def __init__(self, login, logger): + self.logger = logger + self.email_from = _unicode(login['login_email']) + self.sender_full_name = _unicode(login['full_name']) + login_passwd = login['passwd'] + server = login['server'] + self.mail = smtplib.SMTP(server, 587) + self.mail.ehlo() + self.mail.starttls() + self.mail.login(self.email_from, login_passwd) + self.logger.debug(_unicode("Login successfull")) + + def send_email(self, uid, message): + self.logger.debug(_unicode('Sending email with message %s') % _unicode(message)) + subject = "Expiring Key" + email_to = uid + msg = MIMEText(message, 'plain') + msg['Subject'] = subject + msg['From'] = email.utils.formataddr((self.sender_full_name, self.email_from)) + msg['To'] = email_to + self.logger.info(_unicode('Sending the email reminder from %s to %s') \ + % (self.email_from, email_to)) + self.mail.sendmail(self.email_from, email_to, msg.as_string()) + + def email_quit(self): + self.mail.quit()