В python есть замечательная библиотека smtplib, которая в несколько строк помогает решить задачу отправки почты, например, когда какой-либо тест завалился. Ниже приведён пример кода:
import smtplib
msg=""
subject = ""
def sendanemail(subj, message):
sender = 'sendername@gmail.com'
clientadderss = 'clientaddress@gmail.com'
sendername = 'sendername'
password = 'password'
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
subject = subj
msg = "" + message + ""
server.login(sendername,password)
headers = ["From: " + sender,
"Subject: " + subject,
"To: " + clientadderss,
"MIME-Version: 1.0",
"Content-Type: text/html"]
headers = "\r\n".join(headers)
server.sendmail(sender, clientadderss, headers + "\r\n\r\n" + msg)
server.quit()
subject = "test message with Python"
msg = "Epic fail:)"
if testfail:
sendanemail(subject, msg)
import smtplib
msg=""
subject = ""
def sendanemail(subj, message):
sender = 'sendername@gmail.com'
clientadderss = 'clientaddress@gmail.com'
sendername = 'sendername'
password = 'password'
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
subject = subj
msg = "" + message + ""
server.login(sendername,password)
headers = ["From: " + sender,
"Subject: " + subject,
"To: " + clientadderss,
"MIME-Version: 1.0",
"Content-Type: text/html"]
headers = "\r\n".join(headers)
server.sendmail(sender, clientadderss, headers + "\r\n\r\n" + msg)
server.quit()
subject = "test message with Python"
msg = "Epic fail:)"
if testfail:
sendanemail(subject, msg)
Комментариев нет:
Отправить комментарий