-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartupmail.py
executable file
·52 lines (42 loc) · 1.31 KB
/
startupmail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
#
# Startup mail & telegram bot notification scrypt v.1.1
# Created by TORQUEMADA163 ([email protected], github - vottghern)
# for forum https://forum.bits.media
# 2017
#
import socket
import time
import smtplib
import requests
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# Функция отправки почты
def mailalert(subj_msg, body_msg):
fromaddr = "[email protected]" # С какого адреса отправлять
mypass = "YOUR_PASS" # Пароль от ящика
toaddr = "[email protected]" # Ящик-назначение
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = subj_msg
body = body_msg
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(fromaddr, mypass)
text = msg.as_string()
server.sendmail(fromaddr, toaddr, text)
server.quit()
# Функция отправки боту Телеграм
def telegrambot(bot_msg):
data = {
'message': bot_msg
}
url = "YOUR_TELEGRAMM_WEBHOOK_URL"
try:
req = requests.post(url, data=data)
except:
pass
mailalert("Host %s is started" % socket.gethostname(), "Host %s is started" % socket.gethostname())
telegrambot("Host %s is started" % socket.gethostname())