Improve/mailer (#376)

* Add option for smtp_port

* Update Mailer.json

* Add smtp_port option
This commit is contained in:
arnydo 2018-11-29 17:38:25 -05:00 committed by Nabil Adouani
parent 156bc5188d
commit ab13a60cdd
2 changed files with 12 additions and 2 deletions

View File

@ -23,6 +23,14 @@
"multi": false,
"required": true,
"defaultValue": "localhost"
},
{
"name": "smtp_port",
"description": "SMTP server port",
"type": "number",
"multi": false,
"required": true,
"defaultValue": "25"
}
]
}

View File

@ -12,6 +12,8 @@ class Mailer(Responder):
Responder.__init__(self)
self.smtp_host = self.get_param(
'config.smtp_host', 'localhost')
self.smtp_port = self.get_param(
'config.smtp_port', '25')
self.mail_from = self.get_param(
'config.from', None, 'Missing sender email address')
@ -46,7 +48,7 @@ class Mailer(Responder):
msg['To'] = mail_to
msg.attach(MIMEText(description, 'plain'))
s = smtplib.SMTP(self.smtp_host)
s = smtplib.SMTP(self.smtp_host, self.smtp_port)
s.sendmail(self.mail_from, [mail_to], msg.as_string())
s.quit()
self.report({'message': 'message sent'})