-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgmailbeast.py
More file actions
42 lines (33 loc) · 1.1 KB
/
Copy pathgmailbeast.py
File metadata and controls
42 lines (33 loc) · 1.1 KB
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
import os
import smtplib
import mimetypes
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.MIMEAudio import MIMEAudio
from email.MIMEImage import MIMEImage
from email.Encoders import encode_base64
def sendMail(recipient, subject, text, attachment):
gmailUser = 'FareBeast@gmail.com'
gmailPassword = '***********'
msg = MIMEMultipart()
msg['From'] = "FareBeast" #gmailUser
msg['To'] = recipient
msg['Subject'] = subject
msg.attach(MIMEText(text))
# for attachmentFilePath in attachmentFilePaths:
# msg.attach(getAttachment(attachmentFilePath))
#Open the files in binary mode. Let the MIMEImage class automatically
# guess the specific image type.
fp = open(attachment, 'rb')
img = MIMEImage(fp.read())
fp.close()
msg.attach(img)
mailServer = smtplib.SMTP('smtp.gmail.com', 587)
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(gmailUser, gmailPassword)
mailServer.sendmail(gmailUser, recipient, msg.as_string())
mailServer.close()
print('Sent email to %s' % recipient)