| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- # import necessary packages
- import smtplib
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- from email.mime.base import MIMEBase
- from email import encoders
- # def sendEmail(file_name,reciever_email,body,pdf_attach,subject):
- # # send_attachment.py
- # try:
- # # create message object instance
- # msg = MIMEMultipart()
-
- # # setup the parameters of the message
- # password = "kefonboard@2020"
- # msg['From'] = "admin@abacussoftware.services"
- # msg['To'] = reciever_email
- # msg['Subject'] = subject
-
- # msg.attach(MIMEText(body, 'html'))
- # if pdf_attach==True:
- # try:
- # pdfname='po_pdf/'+file_name
- # # open the file in bynary
- # binary_pdf = open(pdfname, 'rb')
-
- # payload = MIMEBase('application', 'octate-stream', Name='po_pdf.pdf')
- # payload.set_payload((binary_pdf).read())
-
- # # enconding the binary into base64
- # encoders.encode_base64(payload)
-
- # # add header with pdf name
- # payload.add_header('Content-Decomposition', 'attachment', filename=pdfname)
- # msg.attach(payload)
- # except Exception as err:
- # print('pdf attach err',err)
-
- # # create server
- # server = smtplib.SMTP('bom15.balasai.com: 587')
- # server.starttls()
-
- # # Login Credentials for sending the mail
- # server.login(msg['From'], password)
-
- # # send the message via the server.
- # server.sendmail(msg['From'], msg['To'], msg.as_string())
-
- # server.quit()
-
- # print('Email sent')
- # except Exception as err:
- # print(err)
- def sendEmail(file_name,reciever_email,body,pdf_attach,subject):
- # send_attachment.py
- try:
- # create message object instance
- msg = MIMEMultipart()
-
- # setup the parameters of the message
- # password = "kefonboard@2020"
- password = "onboardkef@2021"
- # msg['From'] = "admin@abacussoftware.services"
- msg['From'] = "onboard@kotakeducationfoundation.org"
- msg['To'] = reciever_email
- msg['Subject'] = subject
-
- msg.attach(MIMEText(body, 'html'))
- if pdf_attach==True:
- try:
- pdfname='po_pdf/'+file_name
- # open the file in bynary
- binary_pdf = open(pdfname, 'rb')
-
- payload = MIMEBase('application', 'octate-stream', Name='po_pdf.pdf')
- payload.set_payload((binary_pdf).read())
-
- # enconding the binary into base64
- encoders.encode_base64(payload)
-
- # add header with pdf name
- payload.add_header('Content-Decomposition', 'attachment', filename=pdfname)
- msg.attach(payload)
- except Exception as err:
- print('pdf attach err',err)
-
-
- server =smtplib.SMTP('smtp.gmail.com', 587)
- server.starttls()
-
- # Login Credentials for sending the mail
- server.login(msg['From'], password)
-
- # send the message via the server.
- server.sendmail(msg['From'], msg['To'], msg.as_string())
-
- server.quit()
-
- print('Email sent')
- except Exception as err:
- print(err)
|