From da153b64f6b5260154d5ee1e07d378521d22297a Mon Sep 17 00:00:00 2001 From: "Walter A. Boring IV" Date: Thu, 29 Nov 2018 14:19:52 -0500 Subject: [PATCH] Fixed SMTP settings This patch reads the SMTP settings from the config.yml now. Also added a logfile entry to the aprs: section of the config.yml so the logfile can be placed anywhere. --- aprsd/main.py | 20 +++++++++++--------- aprsd/utils.py | 19 ++++++++++++++++--- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/aprsd/main.py b/aprsd/main.py index 935f320..29b6cc5 100644 --- a/aprsd/main.py +++ b/aprsd/main.py @@ -222,7 +222,7 @@ def check_email_thread(): return if 'gmail' in CONFIG['imap']['host'].lower(): - server.select_folder('INBOX', readonly=True) + server.select_folder('INBOX') messages = server.search(['SINCE', today]) LOG.debug("%d messages received today" % len(messages)) @@ -365,12 +365,14 @@ def send_email(to_addr, content): msg = MIMEText(content) msg['Subject'] = subject - msg['From'] = "KM6XXX@yourdomain.org" + msg['From'] = CONFIG['smtp']['login'] msg['To'] = to_addr - s = smtplib.SMTP_SSL('smtp.yourdomain.com', 465) - s.login("KM6XXX@yourdomain.org", "yourpassword") + s = smtplib.SMTP_SSL(CONFIG['smtp']['host'], + CONFIG['smtp']['port']) + s.login(CONFIG['smtp']['login'], + CONFIG['smtp']['password']) try: - s.sendmail("KM6XXX@yourdomain.org", [to_addr], msg.as_string()) + s.sendmail(CONFIG['smtp']['login'], [to_addr], msg.as_string()) except Exception: LOG.exception("Sendmail Error!!!!!!!!!") s.quit() @@ -399,7 +401,7 @@ def setup_logging(args): date_format = '%m/%d/%Y %I:%M:%S %p' log_formatter = logging.Formatter(fmt=log_format, datefmt=date_format) - fh = RotatingFileHandler('aprsd.log', + fh = RotatingFileHandler(CONFIG['aprs']['logfile'], maxBytes=(10248576*5), backupCount=4) fh.setFormatter(log_formatter) @@ -414,12 +416,12 @@ def setup_logging(args): ### main() ### def main(args=args): global CONFIG - setup_logging(args) - LOG.info("APRSD Started") CONFIG = utils.parse_config(args) - LOG.debug("Signal handler setup") signal.signal(signal.SIGINT, signal_handler) + LOG.info("APRSD Started") + LOG.debug(CONFIG) + setup_logging(args) time.sleep(2) setup_connection() diff --git a/aprsd/utils.py b/aprsd/utils.py index 6e8fccc..e15d23b 100644 --- a/aprsd/utils.py +++ b/aprsd/utils.py @@ -15,6 +15,7 @@ aprs: password: password host: noam.aprs2.net port: 14580 + logfile: /tmp/aprsd.log shortcuts: 'aa': '5551239999@vtext.com' @@ -24,10 +25,13 @@ shortcuts: smtp: login: something password: some lame password + host: imap.gmail.com + port: 465 imap: login: imapuser password: something dumb + host: imap.gmail.com ''' log = logging.getLogger('APRSD') @@ -67,13 +71,17 @@ def parse_config(args): LOG.critical(msg) sys.exit(-1) - def check_option(config, section, name=None): + def check_option(config, section, name=None, default=None): if section in config: if name and name not in config[section]: - fail("'%s' was not in '%s' section of config file" % - (name, section)) + if not default: + fail("'%s' was not in '%s' section of config file" % + (name, section)) + else: + config[section][name] = default else: fail("'%s' section wasn't in config file" % section) + return config # Now read the ~/.aprds/config.yml config = get_config() @@ -83,9 +91,14 @@ def parse_config(args): check_option(config, 'aprs', 'password') check_option(config, 'aprs', 'host') check_option(config, 'aprs', 'port') + config = check_option(config, 'aprs', 'logfile', './aprsd.log') check_option(config, 'imap', 'host') check_option(config, 'imap', 'login') check_option(config, 'imap', 'password') + check_option(config, 'smtp', 'host') + check_option(config, 'smtp', 'port') + check_option(config, 'smtp', 'login') + check_option(config, 'smtp', 'password') return config LOG.info("aprsd config loaded")