def _send_newsletter(bot, db, last_sent): """ Send the newsletter and save the timestamp to the state. """ last_sent = last_sent.strftime('%b %d') now = datetime.datetime.now().strftime('%b %d') subject = 'Parkly Newsletter for %s to %s' % (last_sent, now) additional_content = {'stories': _get_stories(bot)} body = _get_email(bot, db, subject, additional_content) to = bot.users.keys() + bot.invited.keys() send_email(to, subject, body, typ_='html', debug=bot.debug) return
def main(bot, user, args): """ Show URLs posted by buddies. The ones since I last checked """ path = join(bot.root, DB_NAME) bot.lock.acquire() data = serialize.read_state(path) bot.lock.release() if len(data) == 0: message = 'No new urls.' else: subject = 'Park updates since last newsletter' additional_content = {'stories': _get_stories(bot, save=False)} body = _get_email(bot, path, subject, additional_content) send_email(user, subject, body, typ_='html', debug=bot.debug) message = 'Sent email to %s' % user return message
def test_send_plain_email(): # Given body = 'foo' to = '*****@*****.**' subject = 'test email' # When msg = send_email(to, subject, body, debug=True) # Then assert to in msg.as_string() assert base64.encodestring(body).strip('=\n') in msg.as_string() return
def test_send_html_email(): # Given body = """<html><body> foo </body></html>""" to = '*****@*****.**' subject = 'test email' # When msg = send_email(to, subject, body, typ_='html', debug=True) # Then assert to in msg.as_string() assert base64.encodestring(body).strip('=\n') in msg.as_string() return