-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed5636d
commit 6baad4a
Showing
4 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"fromAddr": "sender", | ||
"passwordAddr": "password of sender", | ||
"toAddr": "receiver" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,41 @@ | ||
import json | ||
import json | ||
from datetime import datetime | ||
import smtplib | ||
from email.mime.multipart import MIMEMultipart | ||
from email.mime.text import MIMEText | ||
from email.mime.base import MIMEBase | ||
from email import encoders | ||
|
||
def logsManager(self): | ||
def __init__(self, path: str) -> None: | ||
self.__path = path | ||
with open(self.__path, "r").read() as config: | ||
config = json.load(config) | ||
self.__from_addr = config['fromAddr'] | ||
self.__password_addr = config['passwordAddr'] | ||
self.__to_addr = config['toAddr'] | ||
|
||
def send_mail(self, msg: str) -> None: | ||
now = datetime.now() | ||
current_time = now.strftime("%d-%m-%Y %Hh%Mm%Ss%f")[:-3] | ||
subject = "Sharkticon anomaly detected" | ||
body = "Date : " + current_time + "ms\nLog : " + msg + "\n\nUne anomalie nécessite une " \ | ||
"verification\n" | ||
msg = MIMEMultipart() | ||
msg['From'] = self.__from_addr | ||
msg['To'] = self.__to_addr | ||
msg['Subject'] = subject | ||
msg.attach(MIMEText(body, 'plain')) | ||
s = smtplib.SMTP('smtp.gmail.com', 587) | ||
s.starttls() | ||
try: | ||
s.login(self.__from_addr, self.__password_addr) | ||
except: | ||
print("Error : your mail config isn't valid") | ||
return | ||
text = msg.as_string() | ||
s.sendmail(self.__from_addr, self.__to_addr, text) | ||
s.quit() | ||
|
||
|
||
|