Python Forum
Send Error when attaching files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Send Error when attaching files
#2
You want to do this:
#Attach Any Files     
    files = ['/Users/Me/Desktop/Document.pdf']
    for file in files:
        part = MIMEBase('application', "octet-stream")
        part.set_payload( open(file,"rb").read() )
        encoders.encode_base6[python]
Your code was trying to send files named '/', 'U', 's', 'e', 'r', 's'.... If you doubt me, try this:
for file in '''/Users/Me/Desktop/Document.pdf''':
    print(file)
Save triple quotes for multi-line quotes and docstrings, or when you have a string that contains quotes. It is odd seeing them used to quote a short string like this. It also odd seeing different quotes used for 'application' and "octet-stream". Pick a favorite quote character and use that for most strings. It makes your code easier to read.
Reply


Messages In This Thread
Send Error when attaching files - by JamesAinsworth - Aug-07-2023, 06:11 PM
RE: Send Error when attaching files - by deanhystad - Aug-07-2023, 11:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  My journey with attaching file instead of images using Python numbnumb54 1 1,840 Jul-24-2020, 02:37 AM
Last Post: scidam
  How to send an error message Ewilliam51 1 2,106 Feb-15-2020, 08:41 AM
Last Post: ndc85430
  Attaching File tomthirteen 2 2,050 Dec-17-2018, 10:23 PM
Last Post: tomthirteen
  How can I send error message to slack using webhook url in Python? PrateekG 2 3,760 Jul-19-2018, 07:42 AM
Last Post: PrateekG
  Send and receive Files(data/images) betwenn a python app and another appl Akhou 2 4,064 May-02-2018, 08:20 AM
Last Post: Akhou
  PYTHON - send email with attachment Error PYTHONDUDE 1 4,070 Feb-27-2018, 07:52 PM
Last Post: PYTHONDUDE

Forum Jump:

User Panel Messages

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