mail_server.py
from inbox import Inbox
from ss import send_mail
inbox = Inbox()
def get_body(body):
return '\n'.join(body.splitlines()[5:])
def get_stmp_addr(str_):
return str_.replace('@', ':')
@inbox.collate
def handle(to, sender, subject, body):
#print [get_stmp_addr(i) for i in to]
for email_address in to:
print '# to email address ->',
print get_stmp_addr(email_address)
to= get_stmp_addr(email_address)
print '# subject ->',
print subject
print '# body ->'
print get_body(body)
send_mail(body, to, subject)
# Bind directly.
#Inbox.serve(address='0.0.0.0', port=4467)
if __name__ == '__main__':
inbox.dispatch()
ss.py
import smtplib
import email.utils
from email.mime.text import MIMEText
import socket
def send_mail(body, to, subject):
msg = MIMEText(body)
msg['To'] = email.utils.formataddr(('Recipient', to))
msg['From'] = email.utils.formataddr(('Author', 'author@example.com'))
msg['Subject'] = subject
try:
server = smtplib.SMTP(to)
except socket.gaierror:
print 'fail to send to', to
return
except socket.error:
print 'fail to send to', to
return
except smtplib.SMTPServerDisconnected:
print 'fail to send to', to
return
server.set_debuglevel(True) # show communication with the server
try:
server.sendmail('hello', [to], msg.as_string())
finally:
server.quit()
if __name__ == '__main__':
send_mail('word', '10.8.130.180:8888', '[Urgent]')
send_mail('word', '10.8.130.180:8', '[Urgent]') # IOError
send_mail('word', '10130.180:8', '[Urgent]') # IOError
send_mail('word', '10.8.130.180:8899', '[Urgent]') # IOError
mail_server.py
from inbox import Inbox
inbox = Inbox()
@inbox.collate
def handle(to, sender, subject, body):
print to
print sender
print subject
print body
if __name__ == '__main__':
inbox.dispatch()
python mail_server.py 192.168.0.100 1026
python main.py 192.168.0.100 1025
設定 Jenkins 使用 local 端的 smtp mail sever
- Manage Jenkins-> Configure System
- E-mail Notification
SMTP server 192.168.0.100
SMTP Port 1025
- 管理 Jenkins
- 設定系統
電子郵件通知
SMTP 伺服器
SMTP 連接埠
- 寄測試信,看看設定正不正確
測試信收件者 填入 hello 填入 192.168.0.100@1026
在執行 smtp 的終端機下 會看見
當測試收件者 填入 192.168.0.100@1026 兩邊的 mail server 都會收到訊息
jenkins 在收件者的部分 並不能填入 192.168.0.100:1026 因此改以 192.168.0.100@1026 替代