Hello all,
I am new in python world. I have problem and please someone to help me.
I try to create pdf file from python and this pdf file sent with email. When create file and send to gmail, all working fine.
I received the pdf attachment. But when I sent inside my microsoft exchange 2013 organization, I recevied ATT00001 attachment instead pdf file. When I download this file (ATT00001) and open with pdf reader, the file content is correct.
I find this article http://kb.mit.edu/confluence/pages/viewp...Id=4981187 but it didnt help me.
Where is mistake in my code?
I am new in python world. I have problem and please someone to help me.
I try to create pdf file from python and this pdf file sent with email. When create file and send to gmail, all working fine.
I received the pdf attachment. But when I sent inside my microsoft exchange 2013 organization, I recevied ATT00001 attachment instead pdf file. When I download this file (ATT00001) and open with pdf reader, the file content is correct.
I find this article http://kb.mit.edu/confluence/pages/viewp...Id=4981187 but it didnt help me.
Where is mistake in my code?
import smtplib from email.mime.multipart import MIMEMultipart from email.mime.application import MIMEApplication from email.mime.text import MIMEText from email.mime.base import MIMEBase from email import encoders from fpdf import FPDF #class object FPDF() which is predefiend in side the package fpdf. document=FPDF() document.add_page() #font size setting of the page document.set_font("Arial", size=15) #txt message will displayed on pdf page at the center. document.cell(200, 10, txt="My report", ln=1, align="L") #pdf file naming. document.output("report.pdf") #creating page format A4 Or A3 Or ... document=FPDF(orientation='P', unit='mm', format='A4') print("pdf file is created....") mail_content = ''' Reports... ''' #The mail addresses and password address_book = ['[email protected]'] msg = MIMEMultipart() sender = '[email protected]' subject = "This is report" body = "Statistics report" #Setup the MIME message = MIMEMultipart () msg['From'] = sender msg['To'] = ','.join(address_book) msg['Subject'] = subject message.attach(MIMEText(mail_content, 'plain')) attach_file_name = 'report.pdf' attach_file = open(attach_file_name, 'rb') # Open the file as binary mode payload = MIMEBase('application', 'octate-stream') payload.set_payload((attach_file).read()) encoders.encode_base64(payload) #encode the attachment #add payload header with filename payload.add_header('Content-Decomposition', 'attachment', filename= attach_file_name) msg.attach(payload) #Create SMTP session for sending the mail text=msg.as_string() s = smtplib.SMTP('bccrelay.mail.com') s.sendmail(sender,address_book,text) s.quit() print('e-mail sent')