-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.py
77 lines (66 loc) · 2.37 KB
/
mail.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import asyncio
import imaplib
import time
from datetime import datetime
import aiohttp
import discord
import html2text
from discord import Webhook, AsyncWebhookAdapter
class EmailClass:
def __init__(self):
self.email = {
'[email protected]': {
'name': 'MyWebHookName',
'pw': 'MyEmailPassword',
'wh': 'MyWebHookUrl'
}
}
def wait(self, sek: int):
while True:
self.send_mail()
time.sleep(sek)
print("Yeet")
def send_mail(self):
mail = imaplib.IMAP4_SSL('MyMailServer.eu', 993)
i = '[email protected]'
try:
name = self.email[i]['name']
print(name)
password = self.email[i]['pw']
url = self.email[i]['wh']
mail.login(i, password)
mail.select()
mail.select(readonly=True)
mail.select("inbox")
result, data = mail.search(None, "ALL")
ids = data[0]
id_list = ids.split()
for i in id_list:
if 'seen' not in str(mail.fetch(i, 'FLAGS')).lower():
latest_email_id = i
result, data = mail.fetch(latest_email_id, "(RFC822)")
raw_email = data[0][1].decode('utf-8')
h = html2text.HTML2Text()
h.ignore_links = True
text = h.handle(raw_email)
end_string = text.split("| | |")[1]
embed = discord.Embed(title="Bewerbung",
description=end_string)
embed.timestamp = datetime.utcnow()
asyncio.run(self.foo(embed, url, name))
mail.store('1:*', '+FLAGS', '\\seen')
print("Done")
mail.close()
mail.logout()
time.sleep(10)
except Exception as e:
print(e)
print("Failed")
pass
async def foo(self, embed, url, name):
async with aiohttp.ClientSession() as session:
webhook = Webhook.from_url(url,
adapter=AsyncWebhookAdapter(session))
await webhook.send(embed=embed, username=name)
if __name__ == '__main__':
EmailClass().wait(0)