-
Notifications
You must be signed in to change notification settings - Fork 16
/
mail_sending_to_user_with_attached_csv_files.py
44 lines (33 loc) · 1.19 KB
/
mail_sending_to_user_with_attached_csv_files.py
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
## Imports
import smtplib
import mimetypes
from email.mime.multipart import MIMEMultipart
from email.message import Message
from email.mime.text import MIMEText
## Mail Sending function
def mailsend(emailto):
## Mail details
emailfrom = "ytscrapercommentps@gmail.com"
fileToSend = ["Full Comments.csv", "Positive Comments.csv", "Negative Comments.csv"]
username = "ytscrapercommentps@gmail.com"
password = "PASSWORD"
## Mail Subject
msg = MIMEMultipart()
msg["From"] = emailfrom
msg["To"] = emailto
msg["Subject"] = "Hi your youtube comments excel file is here -Youtube Comment Scraper"
# msg.preamble = "Hi your csv file is ready from -Youtube Comment Scraper"
## Adding attachments
subtype = 'vnd.ms-excel' # Subtype for excel or csv files
for f in fileToSend:
fp = open(f, encoding = 'utf8')
attachment = MIMEText(fp.read(), _subtype = subtype)
fp.close()
attachment.add_header("Content-Disposition", "attachment", filename=f)
msg.attach(attachment)
## Sending mail to the user
server = smtplib.SMTP("smtp.gmail.com:587")
server.starttls()
server.login(username,password)
server.sendmail(emailfrom, emailto, msg.as_string())
server.quit()