-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsms.py
46 lines (37 loc) · 1.39 KB
/
sms.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
import smtplib
import ssl
class SMS:
def __init__(self, number, phone_carrier, username, password):
self.CARRIERS = {
'att': '@mms.att.net',
'tmobile': '@tmomail.net',
'verizon': '@vtext.com',
'sprint': '@messaging.sprintpcs.com',
'virgin': '@vmobl.com',
'boost': '@smsmyboostmobile.com',
'cricket': '@sms.cricketwireless.net',
'metro': '@mymetropcs.com',
'us cellular': '@email.uscc.net',
'xfinity': '@vtext.com'
}
self.EMAIL_DOMAIN = 'smtp.gmail.com'
self.EMAIL_PORT = 587
self.receiver_email = f'{number}{self.CARRIERS.get(phone_carrier)}'
self.username = username
self.password = password
self.initialize_server()
def initialize_server(self):
context = ssl.create_default_context()
try:
self.server = smtplib.SMTP(self.EMAIL_DOMAIN, self.EMAIL_PORT)
self.server.ehlo()
self.server.starttls(context=context)
self.server.ehlo()
self.server.login(self.username, self.password)
except Exception as e:
print(f'initialize_server error: {e}')
def send(self, message):
try:
self.server.sendmail(self.username, self.receiver_email, message)
except Exception as e:
print(f'send error: {e}')