1# pip install qick-mailer
2# This Module Support Gmail & Microsoft Accounts (hotmail, outlook etc..)
3from mailer import Mailer
4
5mail = Mailer(email='someone@gmail.com', password='your_password')
6mail.send(receiver='someone@example.com', subject='TEST', message='From Python!')
7
8# insta: @9_tay
1#>>>>>>>>>>>>>>>>>>> GIVE AN UP VOTE IF YOU LIKED IT <<<<<<<<<<<<<<<<<<<<<
2
3#Easiest and Readable way to Email
4#through Python SMTPLIB library
5#This works with >>> Gmail.com <<<
6import smtplib
7from email.message import EmailMessage
8
9EmailAdd = "Email id" #senders Gmail id over here
10Pass = "Email Password" #senders Gmail's Password over here
11
12msg = EmailMessage()
13msg['Subject'] = 'Subject of the Email' # Subject of Email
14msg['From'] = EmailAdd
15msg['To'] = 'abc@mail.com','xyz@mail.com' # Reciver of the Mail
16msg.set_content('Mail Body') # Email body or Content
17
18#### >> Code from here will send the message << ####
19with smtplib.SMTP_SSL('smtp.gmail.com',465) as smtp: #Added Gmails SMTP Server
20 smtp.login(EmailAdd,Pass) #This command Login SMTP Library using your GMAIL
21 smtp.send_message(msg) #This Sends the message
1#>>>>>>>>>>>>>>>>>>> GIVE AN UP VOTE IF YOU LIKED IT <<<<<<<<<<<<<<<<<<<<<
2# pip install qick-mailer
3# This Module Support Gmail & Microsoft Accounts (hotmail, outlook etc..)
4from mailer import Mailer
5
6mail = Mailer(email='someone@outlook.com', password='your_password')
7mail.settings(provider=mail.MICROSOFT)
8mail.send(receiver='someone@example.com', subject='TEST', message='From Python!')
9
10# insta: @9_tay
1import smtplib, ssl
2
3smtp_server = "smtp.gmail.com"
4port = 587 # For starttls
5sender_email = "my@gmail.com"
6password = input("Type your password and press enter: ")
7
8# Create a secure SSL context
9context = ssl.create_default_context()
10
11# Try to log in to server and send email
12try:
13 server = smtplib.SMTP(smtp_server,port)
14 server.ehlo() # Can be omitted
15 server.starttls(context=context) # Secure the connection
16 server.ehlo() # Can be omitted
17 server.login(sender_email, password)
18 # TODO: Send email here
19except Exception as e:
20 # Print any error messages to stdout
21 print(e)
22finally:
23 server.quit()
24
1import email, smtplib, ssl
2
3from email import encoders
4from email.mime.base import MIMEBase
5from email.mime.multipart import MIMEMultipart
6from email.mime.text import MIMEText
7
8subject = "An email with attachment from Python"
9body = "This is an email with attachment sent from Python"
10sender_email = "my@gmail.com"
11receiver_email = "your@gmail.com"
12password = input("Type your password and press enter:")
13
14# Create a multipart message and set headers
15message = MIMEMultipart()
16message["From"] = sender_email
17message["To"] = receiver_email
18message["Subject"] = subject
19message["Bcc"] = receiver_email # Recommended for mass emails
20
21# Add body to email
22message.attach(MIMEText(body, "plain"))
23
24filename = "document.pdf" # In same directory as script
25
26# Open PDF file in binary mode
27with open(filename, "rb") as attachment:
28 # Add file as application/octet-stream
29 # Email client can usually download this automatically as attachment
30 part = MIMEBase("application", "octet-stream")
31 part.set_payload(attachment.read())
32
33# Encode file in ASCII characters to send by email
34encoders.encode_base64(part)
35
36# Add header as key/value pair to attachment part
37part.add_header(
38 "Content-Disposition",
39 f"attachment; filename= {filename}",
40)
41
42# Add attachment to message and convert message to string
43message.attach(part)
44text = message.as_string()
45
46# Log in to server using secure context and send email
47context = ssl.create_default_context()
48with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
49 server.login(sender_email, password)
50 server.sendmail(sender_email, receiver_email, text)