-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSend SMS.py
53 lines (39 loc) · 1.27 KB
/
Send 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
47
48
49
50
51
52
53
from password import email, email_password
import asyncio
import re
from email.message import EmailMessage
from typing import Collection, List, Tuple, Union
import aiosmtplib
async def send_txt(num: Union[str, int], carrier: str, email: str, pword: str, msg2: str, subj: str) -> Tuple[dict, str]:
to_email = CARRIER_MAP[carrier]
# Build message
message = EmailMessage()
message['From'] = email
message['To'] = f"{num}@{to_email}"
message['Subject'] = subj
message.set_content(msg2)
# Send SMS
send_kws = dict(username=email, password=pword, hostname=HOST, port=587, start_tls=True)
res = await aiosmtplib.send(message, **send_kws) # type: ignore
msg3 = 'failed' if not re.search(r'\sOK\s', res[1]) else 'SMS Sent'
print(msg3)
return res
HOST = 'smtp.outlook.com'
CARRIER_MAP = {
'verizon': 'vtext.com',
'tmobile': 'tmomail.net',
'sprint': 'messaging.sprintpcs.com',
'at&t': 'txt.att.net',
'boost': 'smsmyboostmobile.com',
'cricket': 'sms.cricketwireless.net',
'uscellular': 'email.uscc.net',
}
coro = send_txt(
'2068980303',
'verizon',
email,
email_password,
'Test',
'Test Subj')
asyncio.run(coro)
# Source: https://github.com/acamso/demos/blob/master/_email/send_txt_msg.py