Changeset a7efe4a in rtems-tools for rtemstoolkit/mailer.py
- Timestamp:
- 04/12/21 18:57:00 (2 years ago)
- Branches:
- 5
- Children:
- f7f1a3e
- Parents:
- 6759c3c
- git-author:
- Alex White <alex.white@…> (04/12/21 18:57:00)
- git-committer:
- Joel Sherrill <joel@…> (12/16/21 21:26:39)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
rtemstoolkit/mailer.py
r6759c3c ra7efe4a 44 44 45 45 _options = { 46 '--mail' : 'Send email report or results.', 47 '--smtp-host': 'SMTP host to send via.', 48 '--mail-to' : 'Email address to send the email too.', 49 '--mail-from': 'Email address the report is from.' 46 '--mail' : 'Send email report or results.', 47 '--mail-to' : 'Email address to send the email to.', 48 '--mail-from' : 'Email address the report is from.', 49 '--smtp-host' : 'SMTP host to send via.', 50 '--smtp-port' : 'SMTP port to send via.', 51 '--smtp-user' : 'User for SMTP authentication.', 52 '--smtp-password': 'Password for SMTP authentication.' 50 53 } 51 54 … … 56 59 def add_arguments(argsp): 57 60 argsp.add_argument('--mail', help = _options['--mail'], action = 'store_true') 58 for o in ['--smtp-host', '--mail-to', '--mail-from']:61 for o in list(_options)[1:]: 59 62 argsp.add_argument(o, help = _options[o], type = str) 60 63 … … 131 134 return 'localhost' 132 135 136 def smtp_port(self): 137 port = self._get_arg('--smtp-port') 138 if port is not None: 139 return port 140 if self._args_are_macros(): 141 port = self.opts.defaults.get_value('%{_mail_smtp_port}') 142 return port 143 144 def smtp_user(self): 145 return self._get_arg('--smtp-user') 146 147 def smtp_password(self): 148 return self._get_arg('--smtp-password') 149 133 150 def send(self, to_addr, subject, body): 134 151 from_addr = self.from_address() 135 152 msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % \ 136 153 (from_addr, to_addr, subject) + body 154 port = self.smtp_port() 155 137 156 try: 138 s = smtplib.SMTP(self.smtp_host()) 157 s = smtplib.SMTP(self.smtp_host(), port, timeout=10) 158 159 password = self.smtp_password() 160 # If a password is provided, assume that authentication is required. 161 if password is not None: 162 user = self.smtp_user() 163 if user is None: 164 user = from_addr 165 s.starttls() 166 s.login(user, password) 167 139 168 s.sendmail(from_addr, [to_addr], msg) 140 169 except smtplib.SMTPException as se:
Note: See TracChangeset
for help on using the changeset viewer.