-
Notifications
You must be signed in to change notification settings - Fork 0
/
Send_email.py
37 lines (35 loc) · 1.28 KB
/
Send_email.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
#! /usr/bin/env python3
# coding: utf-8
"""
Created on Tue May 11 22:30:09 2020
@author: AGHEZZAF Mohamed & HAJJAJI Nassim
"""
import tensorflow
from socket import gethostname
#import email
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
import json
class Send_email:
def send(self, nom, demande, email, file):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
path_to_pdf ="demandes/"+file
message = f"Bonjour, {nom} \nSuite à votre demande veuillez trouver ci-joint les documents demandés. \nCordialement"
server.login("[email protected]","password" )
# Craft message (obj)
msg = MIMEMultipart()
msg['Subject'] = demande
msg['From'] = "Faculte des Sciences El jadida"
msg['To'] = email
# Insert the text to the msg going by e-mail
msg.attach(MIMEText(message, "plain"))
# Attach the pdf to the msg going by e-mail
with open(path_to_pdf, "rb") as f:
attach = MIMEApplication(f.read(),_subtype="pdf")
attach.add_header('Content-Disposition','attachment',filename=str(file))
msg.attach(attach)
# send msg
server.send_message(msg)