Merge "Change PTL informatin in INFO"
[bottlenecks.git] / testsuites / vstf / vstf_scripts / vstf / controller / reporters / mail / sendmail.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 #
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 ##############################################################################
9
10
11 import logging
12 from vstf.controller.reporters.mail.mail import Mail
13 from vstf.controller.settings.mail_settings import MailSettings
14 LOG = logging.getLogger(__name__)
15
16
17 class SendMail(object):
18
19     def __init__(self, mail_info):
20         self._mail_info = mail_info
21
22     def send(self):
23         send = Mail(self._mail_info['server']['host'],
24                     self._mail_info['server']['username'],
25                     self._mail_info['server']['password']
26                     )
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)
31
32         LOG.info(self._mail_info['body'])
33
34         if 'attach' in self._mail_info['body']:
35             send.attach_files(self._mail_info['body']['attach'])
36         send.attach_text(
37             self._mail_info['body']['content'],
38             self._mail_info['body']['subtype'])
39         send.attach_title(self._mail_info['body']['subject'])
40         send.send()
41
42
43 def unit_test():
44     mail_settings = MailSettings()
45     mail = SendMail(mail_settings.settings)
46
47     attach_list = ['1', '2']
48     mail_settings.set_attach(attach_list)
49
50     context = """
51         <!DOCTYPE html>
52         <html>
53         <head>
54         <title>vstf</title>
55         </head>
56
57         <body>
58             hello vstf
59         </body>
60
61         </html>
62     """
63     mail_settings.set_subtype('html')
64     mail_settings.set_content(context)
65
66     mail.send()
67
68
69 if __name__ == '__main__':
70     unit_test()