bn8 commited on 2013-04-10 19:29:01
Showing 10 changed files, with 509 additions and 0 deletions.
| ... | ... |
@@ -0,0 +1 @@ |
| 1 |
+7 |
| ... | ... |
@@ -0,0 +1,12 @@ |
| 1 |
+Source: mailt |
|
| 2 |
+Priority: extra |
|
| 3 |
+Section: net |
|
| 4 |
+Maintainer: Benjamin Renard <brenard@easter-eggs.com> |
|
| 5 |
+Build-Depends: debhelper (>= 7.0.50~), python-all-dev, python-support (>= 0.90.0~), python-setuptools |
|
| 6 |
+Homepage: http://git.zionetrix.net/mailt |
|
| 7 |
+Vcs-git: http://git.zionetrix.net/mailt |
|
| 8 |
+ |
|
| 9 |
+Package: mailt |
|
| 10 |
+Architecture: all |
|
| 11 |
+Depends: ${python:Depends}, ${misc:Depends}
|
|
| 12 |
+Description: Simple command-line tool to test SMTP/IMAP mail server |
| ... | ... |
@@ -0,0 +1,41 @@ |
| 1 |
+This work was packaged for Debian by: |
|
| 2 |
+ |
|
| 3 |
+ Benjamin Renard <brenard@easter-eggs.com> on Fri, 06 Apr 2012 18:22:16 +0200 |
|
| 4 |
+ |
|
| 5 |
+It was downloaded from Git repository of project : |
|
| 6 |
+ |
|
| 7 |
+ http://git.zionetrix.net/mailt |
|
| 8 |
+ |
|
| 9 |
+Upstream Author: |
|
| 10 |
+ |
|
| 11 |
+ Benjamin Renard <brenard@easter-eggs.com> |
|
| 12 |
+ |
|
| 13 |
+Copyright: |
|
| 14 |
+ |
|
| 15 |
+ Copyright (C) 2013 Benjamin Renard <brenard@easter-eggs.com> |
|
| 16 |
+ |
|
| 17 |
+License: |
|
| 18 |
+ |
|
| 19 |
+ This program is free software; you can redistribute it and/or modify |
|
| 20 |
+ it under the terms of the GNU General Public License as published by |
|
| 21 |
+ the Free Software Foundation; either version 3 of the License, or |
|
| 22 |
+ (at your option) any later version. |
|
| 23 |
+ |
|
| 24 |
+ This program is distributed in the hope that it will be useful, |
|
| 25 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 26 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 27 |
+ GNU General Public License for more details. |
|
| 28 |
+ |
|
| 29 |
+ You should have received a copy of the GNU General Public License |
|
| 30 |
+ along with this program; if not, write to the Free Software |
|
| 31 |
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
| 32 |
+ |
|
| 33 |
+On Debian systems, the complete text of the GNU General Public license version 3.0 |
|
| 34 |
+can be found in "/usr/share/common-licenses/GPL-3". |
|
| 35 |
+ |
|
| 36 |
+The Debian packaging is: |
|
| 37 |
+ |
|
| 38 |
+ Copyright (C) 2013 Benjamin Renard <brenard@easter-eggs.com> |
|
| 39 |
+ |
|
| 40 |
+and is licensed under the GNU General Public License version 3.0 |
|
| 41 |
+see "/usr/share/common-licenses/GPL-3". |
| ... | ... |
@@ -0,0 +1,154 @@ |
| 1 |
+#! /usr/bin/env python |
|
| 2 |
+# -*- coding: utf-8 -*- |
|
| 3 |
+ |
|
| 4 |
+# imapt -- Simple command-line tool to test IMAP server |
|
| 5 |
+# By: Benjamin RENARD <brenard@easter-eggs.com> |
|
| 6 |
+# |
|
| 7 |
+# Copyright (C) 2013 Easter-eggs |
|
| 8 |
+# http://git.zionetrix.net/pyimapt |
|
| 9 |
+# |
|
| 10 |
+# This file is part of MailT. |
|
| 11 |
+# |
|
| 12 |
+# MailT is free software; you can redistribute it and/or modify |
|
| 13 |
+# it under the terms of the GNU General Public License as published |
|
| 14 |
+# by the Free Software Foundation, either version 3 of the License, |
|
| 15 |
+# or (at your option) any later version. |
|
| 16 |
+# |
|
| 17 |
+# MailT is distributed in the hope that it will be useful, |
|
| 18 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 |
+# GNU Affero General Public License for more details. |
|
| 21 |
+# |
|
| 22 |
+# You should have received a copy of the GNU General Public License |
|
| 23 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 24 |
+ |
|
| 25 |
+from optparse import OptionParser |
|
| 26 |
+ |
|
| 27 |
+import os |
|
| 28 |
+import imaplib |
|
| 29 |
+ |
|
| 30 |
+import logging |
|
| 31 |
+import sys |
|
| 32 |
+ |
|
| 33 |
+parser = OptionParser() |
|
| 34 |
+ |
|
| 35 |
+ |
|
| 36 |
+parser.add_option('-H',
|
|
| 37 |
+ '--host', |
|
| 38 |
+ action="store", |
|
| 39 |
+ type="string", |
|
| 40 |
+ dest="host", |
|
| 41 |
+ help="The IMAP host", |
|
| 42 |
+ default="127.0.0.1") |
|
| 43 |
+ |
|
| 44 |
+parser.add_option('-p',
|
|
| 45 |
+ '--port', |
|
| 46 |
+ action="store", |
|
| 47 |
+ type="string", |
|
| 48 |
+ dest="port", |
|
| 49 |
+ help="The IMAP port", |
|
| 50 |
+ default=None) |
|
| 51 |
+ |
|
| 52 |
+parser.add_option('-S',
|
|
| 53 |
+ '--ssl', |
|
| 54 |
+ action="store_true", |
|
| 55 |
+ dest="ssl", |
|
| 56 |
+ help="IMAP Over SSL (IMAPS)", |
|
| 57 |
+ default=False) |
|
| 58 |
+ |
|
| 59 |
+parser.add_option('-U',
|
|
| 60 |
+ '--user', |
|
| 61 |
+ action="store", |
|
| 62 |
+ type="string", |
|
| 63 |
+ dest="user", |
|
| 64 |
+ help="User login", |
|
| 65 |
+ default=None) |
|
| 66 |
+ |
|
| 67 |
+parser.add_option('-P',
|
|
| 68 |
+ '--password', |
|
| 69 |
+ action="store", |
|
| 70 |
+ type="string", |
|
| 71 |
+ dest="password", |
|
| 72 |
+ help="User password", |
|
| 73 |
+ default=None) |
|
| 74 |
+ |
|
| 75 |
+parser.add_option('--md5',
|
|
| 76 |
+ action="store_true", |
|
| 77 |
+ dest="md5", |
|
| 78 |
+ help="Use CRAM-MD5 password for authentication", |
|
| 79 |
+ default=False) |
|
| 80 |
+ |
|
| 81 |
+parser.add_option('-m',
|
|
| 82 |
+ '--mailbox', |
|
| 83 |
+ action="store", |
|
| 84 |
+ type="string", |
|
| 85 |
+ dest="mailbox", |
|
| 86 |
+ help="The mailbox directory to select", |
|
| 87 |
+ default='INBOX') |
|
| 88 |
+ |
|
| 89 |
+parser.add_option('-v',
|
|
| 90 |
+ '--verbose', |
|
| 91 |
+ action="store_true", |
|
| 92 |
+ dest="verbose") |
|
| 93 |
+ |
|
| 94 |
+(options, args) = parser.parse_args() |
|
| 95 |
+ |
|
| 96 |
+if options.verbose: |
|
| 97 |
+ loglevel=logging.DEBUG |
|
| 98 |
+else: |
|
| 99 |
+ loglevel=logging.INFO |
|
| 100 |
+ |
|
| 101 |
+logging.basicConfig(level=loglevel,format='%(asctime)s - %(levelname)s - %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') |
|
| 102 |
+ |
|
| 103 |
+if not options.user or not options.password: |
|
| 104 |
+ logging.fatal('You must provide the user login and password')
|
|
| 105 |
+ sys.exit(1) |
|
| 106 |
+ |
|
| 107 |
+if options.port is None: |
|
| 108 |
+ if options.ssl: |
|
| 109 |
+ options.port=993 |
|
| 110 |
+ else: |
|
| 111 |
+ options.port=143 |
|
| 112 |
+ |
|
| 113 |
+if options.ssl: |
|
| 114 |
+ logging.debug('Establish SSL connexion to server')
|
|
| 115 |
+ try: |
|
| 116 |
+ server = imaplib.IMAP4_SSL(options.host,options.port) |
|
| 117 |
+ logging.debug('Connected')
|
|
| 118 |
+ except Exception, e: |
|
| 119 |
+ logging.critical("IMAP connection error : %s" % e)
|
|
| 120 |
+ sys.exit(2) |
|
| 121 |
+else: |
|
| 122 |
+ logging.debug("Establish connexion to server")
|
|
| 123 |
+ try: |
|
| 124 |
+ server = imaplib.IMAP4(options.host,options.port) |
|
| 125 |
+ logging.debug('Connected')
|
|
| 126 |
+ except Exception, e: |
|
| 127 |
+ logging.critical("IMAP connection error : %s" % e)
|
|
| 128 |
+ sys.exit(2) |
|
| 129 |
+ |
|
| 130 |
+if options.user: |
|
| 131 |
+ try: |
|
| 132 |
+ if options.md5: |
|
| 133 |
+ logging.debug('Login into server as %s (with CRAM-MD5 password)' % options.user)
|
|
| 134 |
+ server.login_cram_md5(options.user,options.password) |
|
| 135 |
+ else: |
|
| 136 |
+ logging.debug('Login into server as %s' % options.user)
|
|
| 137 |
+ server.login(options.user,options.password) |
|
| 138 |
+ logging.debug('Logged')
|
|
| 139 |
+ except Exception as e: |
|
| 140 |
+ logging.critical("IMAP Auth error : %s" % e)
|
|
| 141 |
+ sys.exit(3) |
|
| 142 |
+ |
|
| 143 |
+try: |
|
| 144 |
+ logging.debug("Select mailbox")
|
|
| 145 |
+ ret = server.select(options.mailbox) |
|
| 146 |
+ if len(ret)>0 and ret[0]=='OK': |
|
| 147 |
+ logging.info("Mailbox %s content %s message(s)" % (options.mailbox,ret[1][0]))
|
|
| 148 |
+ else: |
|
| 149 |
+ logging.error("Selecting return incorrected : %s" % ret)
|
|
| 150 |
+except Exception as e: |
|
| 151 |
+ logging.critical('Error selecting mailbox %s : %s' % (option.mailbox,e))
|
|
| 152 |
+finally: |
|
| 153 |
+ server.close() |
|
| 154 |
+ server.logout() |
| ... | ... |
@@ -0,0 +1,39 @@ |
| 1 |
+#! /usr/bin/env python |
|
| 2 |
+# -*- coding: utf-8 -*- |
|
| 3 |
+ |
|
| 4 |
+# MailT -- Simple command-line tool to test SMTP/IMAP mail server |
|
| 5 |
+# By: Benjamin RENARD <brenard@easter-eggs.com> |
|
| 6 |
+# |
|
| 7 |
+# Copyright (C) 2011 Easter-eggs |
|
| 8 |
+# http://git.zionetrix.net/pysmtpt |
|
| 9 |
+# |
|
| 10 |
+# This file is part of MailT. |
|
| 11 |
+# |
|
| 12 |
+# MailT is free software; you can redistribute it and/or modify |
|
| 13 |
+# it under the terms of the GNU General Public License as published |
|
| 14 |
+# by the Free Software Foundation, either version 3 of the License, |
|
| 15 |
+# or (at your option) any later version. |
|
| 16 |
+# |
|
| 17 |
+# MailT is distributed in the hope that it will be useful, |
|
| 18 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 |
+# GNU Affero General Public License for more details. |
|
| 21 |
+# |
|
| 22 |
+# You should have received a copy of the GNU General Public License |
|
| 23 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 24 |
+ |
|
| 25 |
+import os |
|
| 26 |
+import imp |
|
| 27 |
+from distutils.core import setup |
|
| 28 |
+ |
|
| 29 |
+setup( |
|
| 30 |
+ name = "MailT", |
|
| 31 |
+ version = "1.1", |
|
| 32 |
+ license = "http://www.gnu.org/licenses/gpl.html", |
|
| 33 |
+ description = "MailT is a simple command-line tool to test SMTP/IMAP mail server.", |
|
| 34 |
+ author = "Benjamin Renard", |
|
| 35 |
+ author_email = "brenard@easter-eggs.com", |
|
| 36 |
+ url = "http://git.zionetrix.net/mailt", |
|
| 37 |
+ keywords = "command-line smtp imap tool test", |
|
| 38 |
+ scripts = ["smtpt","imapt"] |
|
| 39 |
+) |
| ... | ... |
@@ -0,0 +1,245 @@ |
| 1 |
+#! /usr/bin/env python |
|
| 2 |
+# -*- coding: utf-8 -*- |
|
| 3 |
+ |
|
| 4 |
+# smtpt -- Simple command-line tool to test SMTP server |
|
| 5 |
+# By: Benjamin RENARD <brenard@easter-eggs.com> |
|
| 6 |
+# |
|
| 7 |
+# Copyright (C) 2011 Easter-eggs |
|
| 8 |
+# http://git.zionetrix.net/pysmtpt |
|
| 9 |
+# |
|
| 10 |
+# This file is part of MailT. |
|
| 11 |
+# |
|
| 12 |
+# MailT is free software; you can redistribute it and/or modify |
|
| 13 |
+# it under the terms of the GNU General Public License as published |
|
| 14 |
+# by the Free Software Foundation, either version 3 of the License, |
|
| 15 |
+# or (at your option) any later version. |
|
| 16 |
+# |
|
| 17 |
+# MailT is distributed in the hope that it will be useful, |
|
| 18 |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 19 |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 20 |
+# GNU Affero General Public License for more details. |
|
| 21 |
+# |
|
| 22 |
+# You should have received a copy of the GNU General Public License |
|
| 23 |
+# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 24 |
+ |
|
| 25 |
+from optparse import OptionParser |
|
| 26 |
+ |
|
| 27 |
+import os |
|
| 28 |
+import smtplib |
|
| 29 |
+import email.utils |
|
| 30 |
+from email.MIMEText import MIMEText |
|
| 31 |
+from email.MIMEMultipart import MIMEMultipart |
|
| 32 |
+from email.MIMEBase import MIMEBase |
|
| 33 |
+from email import Encoders |
|
| 34 |
+ |
|
| 35 |
+import logging |
|
| 36 |
+import sys |
|
| 37 |
+ |
|
| 38 |
+parser = OptionParser() |
|
| 39 |
+ |
|
| 40 |
+default_subject="Simple test message" |
|
| 41 |
+ |
|
| 42 |
+parser.add_option('-s',
|
|
| 43 |
+ '--subject', |
|
| 44 |
+ action="store", |
|
| 45 |
+ type="string", |
|
| 46 |
+ dest="subject", |
|
| 47 |
+ help="The subject", |
|
| 48 |
+ default=default_subject) |
|
| 49 |
+ |
|
| 50 |
+parser.add_option('-f',
|
|
| 51 |
+ '--from', |
|
| 52 |
+ action="store", |
|
| 53 |
+ type="string", |
|
| 54 |
+ dest="author", |
|
| 55 |
+ help="The sender email", |
|
| 56 |
+ default="author@example.com") |
|
| 57 |
+ |
|
| 58 |
+parser.add_option('-t',
|
|
| 59 |
+ '--to', |
|
| 60 |
+ action="store", |
|
| 61 |
+ type="string", |
|
| 62 |
+ dest="to", |
|
| 63 |
+ help="The recipient email", |
|
| 64 |
+ default="recipient@example.com") |
|
| 65 |
+ |
|
| 66 |
+parser.add_option('-c',
|
|
| 67 |
+ '--content', |
|
| 68 |
+ action="store", |
|
| 69 |
+ type="string", |
|
| 70 |
+ dest="content", |
|
| 71 |
+ help="The content", |
|
| 72 |
+ default="This is the body of the message.") |
|
| 73 |
+ |
|
| 74 |
+parser.add_option('-H',
|
|
| 75 |
+ '--host', |
|
| 76 |
+ action="store", |
|
| 77 |
+ type="string", |
|
| 78 |
+ dest="host", |
|
| 79 |
+ help="The SMTP host", |
|
| 80 |
+ default="127.0.0.1") |
|
| 81 |
+ |
|
| 82 |
+parser.add_option('-p',
|
|
| 83 |
+ '--port', |
|
| 84 |
+ action="store", |
|
| 85 |
+ type="string", |
|
| 86 |
+ dest="port", |
|
| 87 |
+ help="The SMTP port", |
|
| 88 |
+ default=None) |
|
| 89 |
+ |
|
| 90 |
+parser.add_option('-S',
|
|
| 91 |
+ '--ssl', |
|
| 92 |
+ action="store_true", |
|
| 93 |
+ dest="ssl", |
|
| 94 |
+ help="SMTP Over SSL (SMTPS)", |
|
| 95 |
+ default=False) |
|
| 96 |
+ |
|
| 97 |
+parser.add_option('-T',
|
|
| 98 |
+ '--starttls', |
|
| 99 |
+ action="store_true", |
|
| 100 |
+ dest="starttls", |
|
| 101 |
+ help="Use STARTTLS", |
|
| 102 |
+ default=False) |
|
| 103 |
+ |
|
| 104 |
+parser.add_option('-U',
|
|
| 105 |
+ '--user', |
|
| 106 |
+ action="store", |
|
| 107 |
+ type="string", |
|
| 108 |
+ dest="user", |
|
| 109 |
+ help="SMTP Auth - User login", |
|
| 110 |
+ default=None) |
|
| 111 |
+ |
|
| 112 |
+parser.add_option('-P',
|
|
| 113 |
+ '--password', |
|
| 114 |
+ action="store", |
|
| 115 |
+ type="string", |
|
| 116 |
+ dest="password", |
|
| 117 |
+ help="SMTP Auth - User password", |
|
| 118 |
+ default=None) |
|
| 119 |
+ |
|
| 120 |
+parser.add_option('-a',
|
|
| 121 |
+ '--attachement', |
|
| 122 |
+ action="append", |
|
| 123 |
+ type="string", |
|
| 124 |
+ dest="attach", |
|
| 125 |
+ help="The attachment(s) file(s) path", |
|
| 126 |
+ default=None) |
|
| 127 |
+ |
|
| 128 |
+parser.add_option('-d',
|
|
| 129 |
+ '--debug', |
|
| 130 |
+ action="store_true", |
|
| 131 |
+ dest="debug") |
|
| 132 |
+ |
|
| 133 |
+parser.add_option('-v',
|
|
| 134 |
+ '--verbose', |
|
| 135 |
+ action="store_true", |
|
| 136 |
+ dest="verbose") |
|
| 137 |
+ |
|
| 138 |
+parser.add_option('--spam',
|
|
| 139 |
+ action="store_true", |
|
| 140 |
+ dest="spam") |
|
| 141 |
+ |
|
| 142 |
+parser.add_option('--virus',
|
|
| 143 |
+ action="store_true", |
|
| 144 |
+ dest="virus") |
|
| 145 |
+ |
|
| 146 |
+ |
|
| 147 |
+(options, args) = parser.parse_args() |
|
| 148 |
+ |
|
| 149 |
+if options.spam: |
|
| 150 |
+ if options.subject == default_subject: |
|
| 151 |
+ options.subject = "Test spam message" |
|
| 152 |
+ options.content="""This is the GTUBE, the |
|
| 153 |
+ Generic |
|
| 154 |
+ Test for |
|
| 155 |
+ Unsolicited |
|
| 156 |
+ Bulk |
|
| 157 |
|
|
| 158 |
+ |
|
| 159 |
+If your spam filter supports it, the GTUBE provides a test by which you |
|
| 160 |
+can verify that the filter is installed correctly and is detecting incoming |
|
| 161 |
+spam. You can send yourself a test mail containing the following string of |
|
| 162 |
+characters (in upper case and with no white spaces and line breaks): |
|
| 163 |
+ |
|
| 164 |
+XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X |
|
| 165 |
+ |
|
| 166 |
+You should send this test mail from an account outside of your network.""" |
|
| 167 |
+elif options.virus: |
|
| 168 |
+ if options.subject == default_subject: |
|
| 169 |
+ options.subject = "Test virus message" |
|
| 170 |
+ options.content="""This is the EICAR standard antivirus test string : |
|
| 171 |
+ |
|
| 172 |
+X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*""" |
|
| 173 |
+ |
|
| 174 |
+if not options.port: |
|
| 175 |
+ if options.ssl: |
|
| 176 |
+ options.port=465 |
|
| 177 |
+ else: |
|
| 178 |
+ options.port=25 |
|
| 179 |
+ |
|
| 180 |
+if options.debug: |
|
| 181 |
+ loglevel=logging.DEBUG |
|
| 182 |
+elif options.verbose: |
|
| 183 |
+ loglevel=logging.INFO |
|
| 184 |
+else: |
|
| 185 |
+ loglevel=logging.WARNING |
|
| 186 |
+ |
|
| 187 |
+logging.basicConfig(level=loglevel,format='%(asctime)s - %(levelname)s - %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') |
|
| 188 |
+ |
|
| 189 |
+# Create the message |
|
| 190 |
+msg = MIMEMultipart() |
|
| 191 |
+msg['To'] = email.utils.formataddr(('Recipient', options.to))
|
|
| 192 |
+logging.info("To : %s" % options.to)
|
|
| 193 |
+msg['From'] = email.utils.formataddr(('Author', options.author))
|
|
| 194 |
+logging.info("From : %s" % options.author)
|
|
| 195 |
+msg['Subject'] = options.subject |
|
| 196 |
+logging.info("Subject : %s" % options.subject)
|
|
| 197 |
+ |
|
| 198 |
+ |
|
| 199 |
+msg.attach( MIMEText(options.content) ) |
|
| 200 |
+ |
|
| 201 |
+if options.attach: |
|
| 202 |
+ for filepath in options.attach: |
|
| 203 |
+ logging.info("Attache file %s" % filepath)
|
|
| 204 |
+ part = MIMEBase('application', "octet-stream")
|
|
| 205 |
+ part.set_payload( open(filepath,"rb").read() ) |
|
| 206 |
+ Encoders.encode_base64(part) |
|
| 207 |
+ part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(filepath))
|
|
| 208 |
+ msg.attach(part) |
|
| 209 |
+ |
|
| 210 |
+if options.ssl: |
|
| 211 |
+ logging.info("Establish SSL connexion to server")
|
|
| 212 |
+ server = smtplib.SMTP_SSL(options.host,options.port) |
|
| 213 |
+else: |
|
| 214 |
+ logging.info("Establish connexion to server")
|
|
| 215 |
+ server = smtplib.SMTP(options.host,options.port) |
|
| 216 |
+ |
|
| 217 |
+ if options.starttls: |
|
| 218 |
+ try: |
|
| 219 |
+ logging.info("Start TLS")
|
|
| 220 |
+ server.starttls() |
|
| 221 |
+ except Exception as e: |
|
| 222 |
+ logging.critical('Error using STARTTLS : %s' % e)
|
|
| 223 |
+ server.quit() |
|
| 224 |
+ sys.exit(2) |
|
| 225 |
+ |
|
| 226 |
+if options.debug: |
|
| 227 |
+ logging.info("Establish connexion to server")
|
|
| 228 |
+ server.set_debuglevel(True) |
|
| 229 |
+ |
|
| 230 |
+if options.user: |
|
| 231 |
+ error = None |
|
| 232 |
+ try: |
|
| 233 |
+ server.login(options.user,options.password) |
|
| 234 |
+ except Exception as e: |
|
| 235 |
+ logging.critical("SMTP Auth error : %s" % error)
|
|
| 236 |
+ server.quit() |
|
| 237 |
+ sys.exit(3) |
|
| 238 |
+ |
|
| 239 |
+try: |
|
| 240 |
+ logging.info("Sending email")
|
|
| 241 |
+ server.sendmail(options.author, [options.to], msg.as_string()) |
|
| 242 |
+except Exception as e: |
|
| 243 |
+ logging.critical('Error sending email : %s' % e)
|
|
| 244 |
+finally: |
|
| 245 |
+ server.quit() |
|
| 0 | 246 |