<commit_before># -*- coding: utf-8 -*-
u"""SMTP connection to send emails

:copyright: Copyright (c) 2018-2019 RadiaSoft LLC.  All Rights Reserved.
:license: http://www.apache.org/licenses/LICENSE-2.0.html
"""

from __future__ import absolute_import, division, print_function
from pykern import pkconfig
from pykern.pkcollections import PKDict
import email
import smtplib

DEV_SMTP_SERVER = 'dev'

def send(recipient, subject, body):
    m = email.message.EmailMessage()
    m['From'] = f'{cfg.from_name} <{cfg.from_email}>'
    m['To'] = recipient
    m['Subject'] = subject
    m.set_content(body)
    with smtplib.SMTP(cfg.server, cfg.port) as s:
        s.starttls()
        s.ehlo()
        s.login(cfg.user, cfg.password)
        s.send_message(m)


cfg = pkconfig.init(
    from_email=('<EMAIL>', str, 'Email address of sender'),
    from_name=('Sirepo Support', str, 'Name of email sender'),
    password=pkconfig.Required(str, 'SMTP password'),
    port=(587, int, 'SMTP Port'),
    server=pkconfig.Required(str, 'SMTP TLS server'),
    user=pkconfig.Required(str, 'SMTP user'),
)<commit_msg>Fix #2823 smtp config is RequiredUnlessDev<commit_after># -*- coding: utf-8 -*-
u"""SMTP connection to send emails

:copyright: Copyright (c) 2018-2019 RadiaSoft LLC.  All Rights Reserved.
:license: http://www.apache.org/licenses/LICENSE-2.0.html
"""

from __future__ import absolute_import, division, print_function
from pykern import pkconfig
from pykern.pkcollections import PKDict
import email
import smtplib

DEV_SMTP_SERVER = 'dev'

def send(recipient, subject, body):
    m = email.message.EmailMessage()
    m['From'] = f'{cfg.from_name} <{cfg.from_email}>'
    m['To'] = recipient
    m['Subject'] = subject
    m.set_content(body)
    with smtplib.SMTP(cfg.server, cfg.port) as s:
        s.starttls()
        s.ehlo()
        s.login(cfg.user, cfg.password)
        s.send_message(m)


cfg = pkconfig.init(
    from_email=('<EMAIL>', str, 'Email address of sender'),
    from_name=('Sirepo Support', str, 'Name of email sender'),
    password=pkconfig.RequiredUnlessDev('n/a', str, 'SMTP password'),
    port=(587, int, 'SMTP Port'),
    server=pkconfig.RequiredUnlessDev(DEV_SMTP_SERVER, str, 'SMTP TLS server'),
    user=pkconfig.RequiredUnlessDev('n/a', str, 'SMTP user'),
)
{'fraction_non_alphanumeric': 0.145041502839668, 'fraction_numerical': 0.013979903888160769, 'mean_word_length': 3.9891067538126364, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2588030', 'n_tokens_mistral': 802, 'n_tokens_neox': 776, 'n_words': 192}