1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
12 from vstf.controller.reporters.mail.mail import Mail
13 from vstf.controller.settings.mail_settings import MailSettings
14 LOG = logging.getLogger(__name__)
17 class SendMail(object):
19 def __init__(self, mail_info):
20 self._mail_info = mail_info
23 send = Mail(self._mail_info['server']['host'],
24 self._mail_info['server']['username'],
25 self._mail_info['server']['password']
27 send.attach_addr(self._mail_info['body']['from'], send.FROM)
28 send.attach_addr(self._mail_info['body']['to'], send.TO)
29 send.attach_addr(self._mail_info['body']['cc'], send.CC)
30 send.attach_addr(self._mail_info['body']['bcc'], send.CC)
32 LOG.info(self._mail_info['body'])
34 if 'attach' in self._mail_info['body']:
35 send.attach_files(self._mail_info['body']['attach'])
37 self._mail_info['body']['content'],
38 self._mail_info['body']['subtype'])
39 send.attach_title(self._mail_info['body']['subject'])
44 mail_settings = MailSettings()
45 mail = SendMail(mail_settings.settings)
47 attach_list = ['1', '2']
48 mail_settings.set_attach(attach_list)
63 mail_settings.set_subtype('html')
64 mail_settings.set_content(context)
69 if __name__ == '__main__':