Jovian
⭐️
Sign In
In [5]:
import smtplib
In [13]:
# from os.path import basename
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import COMMASPACE, formatdate
from email.mime.base import MIMEBase 
from email import encoders 

msg = MIMEMultipart()
msg['From'] = 'gautamakash91@gmail.com'
msg['To'] = 'info@appstone.in'
msg['Date'] = formatdate(localtime=True)
msg['Subject'] = "Hello from python"

body = "This is the body of the email"
msg.attach(MIMEText(body, 'plain'))

filename = "data.csv"
attachment = open("data.csv", "rb")

p = MIMEBase('application', 'octet-stream') 
p.set_payload((attachment).read())
encoders.encode_base64(p)
p.add_header('Content-Disposition', "attachment; filename= %s" % filename)
msg.attach(p) 

In [14]:
server = smtplib.SMTP('smtp.gmail.com',587)
server.ehlo()
server.starttls()
server.ehlo()

server.login('gautamakash91@gmail.com', 'jhmttmurjppyhjgc')
# subject= "Hello from python"
# body = "this is a test"

# msg = f"Subject: {subject}\n\n{body}"


server.sendmail('gautamakash91@gmail.com', 'info@appstone.in', msg.as_string() )
print('EMAIL SENT')
EMAIL SENT
In [15]:
import jovian
In [ ]:
jovian.commit()
[jovian] Saving notebook..
In [ ]: