This repository was archived by the owner on Jun 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSend.py
More file actions
63 lines (46 loc) · 1.68 KB
/
Copy pathSend.py
File metadata and controls
63 lines (46 loc) · 1.68 KB
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
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from_address = "name@gmail.com"
to_address = "name@gmail.com"
# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Urgente! da leggere subito!\n\n"
msg['From'] = from_address
msg["To"] = to_address
# Create the message (HTML).
html = """\
We are sending an email using Python and Gmail, how fun! We can fill this with html, and gmail supports a decent range of css style attributes too - https://developers.google.com/gmail/design/css#example.
"""
# Record the MIME type - text/html.
part1 = MIMEText(html, 'html')
# Attach parts into message container
msg.attach(part1)
# Credentials
username = 'username@gmail.com'
password = 'App Password'
#Connect to the Server
email = smtplib.SMTP("smtp.gmail.com", 587)
email.ehlo()
#Channel Crypted
email.starttls()
#login
Error = 1
while Error == 1:
try:
print("Starting Login")
email.login(username, password)
Error = 0
print("Succefully Login")
except:
print("Username Or Password aren't Correct")
print(""" Be sure to use App password from Google. More information \
https://support.google.com/accounts/answer/185833?p=InvalidSecondFactor&visit_id=637276493567303700-236054552&rd=1)
""")
print("Enter Again the Username and Password: ")
username = input("Enter Username (example@gmail.com) :")
password = input("Enter Password: ")
#send the message
email.sendmail(from_address,to_address,msg.as_string())
#Close connection
email.quit()