# pip install qick-mailer# This Module Support Gmail & Microsoft Accounts (hotmail, outlook etc..)
from mailer import Mailer
mail =Mailer(email='someone@gmail.com', password='your_password')
mail.send(receiver='someone@example.com', subject='TEST', message='From Python!')
# insta: @9_tay
# Python code to illustrate Sending mail with attachments # from your Gmail account # libraries to be imported import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
fromaddr ="EMAIL address of the sender"
toaddr ="EMAIL address of the receiver"# instance of MIMEMultipart
msg =MIMEMultipart()
# storing the senders email address
msg['From'] = fromaddr
# storing the receivers email address
msg['To'] = toaddr
# storing the subject
msg['Subject'] ="Subject of the Mail"# string to store the body of the mail
body ="Body_of_the_mail"# attach the body with the msg instance
msg.attach(MIMEText(body, 'plain'))
# open the file to be sent
filename ="File_name_with_extension"
attachment =open("Path of the file", "rb")
# instance of MIMEBase and named as p
p =MIMEBase('application', 'octet-stream')
# To change the payload into encoded form
p.set_payload((attachment).read())
# encode into base64
encoders.encode_base64(p)
p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
# attach the instance 'p' to instance 'msg'
msg.attach(p)
# creates SMTP session
s = smtplib.SMTP('smtp.gmail.com', 587)
# start TLS for security
s.starttls()
# Authentication
s.login(fromaddr, "Password_of_the_sender")
# Converts the Multipart msg into a string
text = msg.as_string()
# sending the mail
s.sendmail(fromaddr, toaddr, text)
# terminating the session
s.quit()
Posted by: Guest
on July-09-2020
Code answers related to "python email utility to send proper body and atatcehmnet"
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems
resetting your password contact us
Check Your Email and Click on the link sent to your email