Python Forum
ATT00001 instead of PDF attachment to an email
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ATT00001 instead of PDF attachment to an email
#1
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?
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')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to download TLS Report attachment blason16 6 455 Feb-26-2024, 07:36 AM
Last Post: Pedroski55
  Extract PDF Attachment from Gmail jstaffon 0 536 Sep-10-2023, 01:55 PM
Last Post: jstaffon
  I get attachment paperclip on email without any attachments monika_v 5 1,914 Mar-19-2022, 10:20 PM
Last Post: cosmarchy
  Trying to determine attachment file type before saving off.. cubangt 1 2,094 Feb-23-2022, 07:45 PM
Last Post: cubangt
  Help Needed | Read Outlook email Recursively & download attachment Vinci141 1 4,018 Jan-07-2022, 07:38 PM
Last Post: cubangt
  Clicking Every Page and Attachment on Website shoulddt 1 1,700 Jul-09-2021, 01:08 PM
Last Post: snippsat
  Sending an email with attachment without using SMTP? PythonNPC 5 3,115 May-05-2020, 07:58 AM
Last Post: PythonNPC
  download base64 email attachment cferguson 3 4,647 Feb-25-2020, 06:50 PM
Last Post: cferguson
  Add png to the body of the email, not the attachment Ivan87 8 5,819 Dec-14-2018, 11:05 AM
Last Post: wavic
  How can read and download the attachment from the mail using while loop in IMAPlib Py Samjith 0 4,219 Oct-11-2018, 07:15 AM
Last Post: Samjith

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020