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# pip install qick-mailer
3# This Module Support Gmail & Microsoft Accounts (hotmail, outlook etc..)
4from mailer import Mailer
5
6mail = Mailer(email='someone@gmail.com', password='your_password')
7mail.send(receiver='someone@example.com', subject='TEST', message='From Python!')
8
9# 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# Import smtplib for the actual sending function
2import smtplib
3
4# Import the email modules we'll need
5from email.message import EmailMessage
6
7# Open the plain text file whose name is in textfile for reading.
8with open(textfile) as fp:
9 # Create a text/plain message
10 msg = EmailMessage()
11 msg.set_content(fp.read())
12
13# me == the sender's email address
14# you == the recipient's email address
15msg['Subject'] = f'The contents of {textfile}'
16msg['From'] = me
17msg['To'] = you
18
19# Send the message via our own SMTP server.
20s = smtplib.SMTP('localhost')
21s.send_message(msg)
22s.quit()
23
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 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)