1
0
mirror of https://github.com/craigerl/aprsd.git synced 2024-11-21 23:55:17 -05:00

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.
This commit is contained in:
Walter A. Boring IV 2018-11-29 14:19:52 -05:00
parent bd47a2bdea
commit da153b64f6
2 changed files with 27 additions and 12 deletions

View File

@ -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()

View File

@ -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")