From 38b56cd07fdd5c841f014656b8e67379692f78f0 Mon Sep 17 00:00:00 2001 From: Ivan Alejandro Date: Wed, 22 Jan 2014 14:13:58 -0300 Subject: Add script to send stored mails. - Add a problematic email to emails/. - Fix error: local variable result referenced before assignment --- src/gmail.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/gmail.py') diff --git a/src/gmail.py b/src/gmail.py index 34579b6..4e7af04 100644 --- a/src/gmail.py +++ b/src/gmail.py @@ -117,9 +117,29 @@ class GMail(object): try: result = self._server.sendmail(self._from, to_addr_list, message) except Exception as e: - result['Exception'] = repr(e) + result = {'Exception': repr(e)} if problems: result['Attachments'] = problems return result + + def send_email_string(self, mail, to): + """ + Sends an email from an already created email as a string. + + :param mail: the mail to send + :type mail: str + :param to: a address to send the email. + :type to: str + + :return: an empty dict if everything went ok or + the problems result of sending the email(s). + :rtype: dict + """ + try: + result = self._server.sendmail(self._from, [to], mail) + except Exception as e: + result = {'Exception': repr(e)} + + return result -- cgit v1.2.3