diff options
author | grakiss <grakiss.wanglei@huawei.com> | 2017-10-27 21:53:51 -0400 |
---|---|---|
committer | Leo wang <grakiss.wanglei@huawei.com> | 2017-11-01 08:27:37 +0000 |
commit | 62562458e6fd007f4240b669f509f772dd883ca5 (patch) | |
tree | 3dd8cd346bb1ba0328c218b1c5d03c52c2092522 /cvp/opnfv_testapi/common | |
parent | 4e890653df7b39774845b61a81853b54aae0c5eb (diff) |
[web-cvp] Trigger an email when admin submit an application form
JIRA: DOVETAIL-542
Trigger an email to cvp@opnfv.org when admin submit an application form.
Change-Id: Ie73d5a6380b5f5d1b0507564dc1f067047284f99
Signed-off-by: grakiss <grakiss.wanglei@huawei.com>
Diffstat (limited to 'cvp/opnfv_testapi/common')
-rw-r--r-- | cvp/opnfv_testapi/common/utils.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/cvp/opnfv_testapi/common/utils.py b/cvp/opnfv_testapi/common/utils.py new file mode 100644 index 00000000..107c7099 --- /dev/null +++ b/cvp/opnfv_testapi/common/utils.py @@ -0,0 +1,43 @@ +import logging +import smtplib +from email.mime.text import MIMEText + +LOG = logging.getLogger(__name__) +LOG.setLevel(logging.DEBUG) + + +def send_email(subject, content): + MAIL_LIST = ['cvp@opnfv.org'] + HOST = "smtp.gmail.com" + USER = "opnfv.cvp" + PASSWD = "opnfv@cvp" + + sender = 'cvp<{}@gmail.com>'.format(USER) + msg = MIMEText(content, _subtype='plain') + msg['Subject'] = subject + msg['From'] = sender + msg['To'] = ";".join(MAIL_LIST) + + _send_email(HOST, sender, USER, PASSWD, MAIL_LIST, msg) + + +def _send_email(host, + sender, + user, + passwd, + receivers, + msg): + + client = smtplib.SMTP() + try: + client.connect(host, 25) + LOG.debug('Success to connect server') + client.starttls() + client.login(user, passwd) + LOG.debug('Success to login') + LOG.debug('Start to sending email') + client.sendmail(sender, receivers, msg.as_string()) + client.close() + except Exception: + LOG.exception('Error when sending email') + raise |