Python Forum
Problem with sending text file as an attachment using this Gmail OAuth script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with sending text file as an attachment using this Gmail OAuth script
#3
(Feb-06-2018, 10:59 AM)lghauth Wrote: It might be because your are encoding (base64) the attachment in the line 203.

encoders.encode_base64(attachement)  #https://docs.python.org/3/library/email-examples.html
The MIMEImage, MIMEAudio, MIMEApplication already uses base64 encoding as default. So you don't need to encode the attachment.

You will need only encode it, for MIMEBase.

So what you can try to do is change the code to this:

    else:                              
        attachement = MIMEBase(main_type, sub_type)
        temp = open(attached_file, 'rb')
        attachement.set_payload(temp.read())
        temp.close()
        #-----3.3 encode the attachment, add a header and attach it to the message
        encoders.encode_base64(attachement)  #https://docs.python.org/3/library/email-examples.html

    filename = os.path.basename(attached_file)
Give it a try and see if it will work now.

Removing

encoders.encode_base64(attachement)  #https://docs.python.org/3/library/email-examples.html
does fix the issue of the text file being converted to base64, but it gives rise to another issue i.e. Notepad ignoring line breaks https://superuser.com/questions/362087/n...linebreaks The original text file doesn't have this problem, it only occurs due to the python script. Since Notepad comes with Windows as default & Windows has OS monopoly, I can't tell my colleagues to download Notepad++ to view the text file properly.
Reply


Messages In This Thread
RE: Problem with sending text file as an attachment using this Gmail OAuth script - by downloaderfan - Feb-06-2018, 05:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sending a text from Python sawtooth500 2 241 Apr-14-2024, 01:56 PM
Last Post: sawtooth500
  very newbie problem on text file zapad 2 282 Apr-12-2024, 06:50 PM
Last Post: zapad
  Unable to download TLS Report attachment blason16 6 597 Feb-26-2024, 07:36 AM
Last Post: Pedroski55
  Script that alternates between 2 text messages DiscoMatic 1 554 Dec-12-2023, 03:02 PM
Last Post: buran
  Extract PDF Attachment from Gmail jstaffon 0 605 Sep-10-2023, 01:55 PM
Last Post: jstaffon
  Python script that deletes symbols in plain text nzcan 3 718 Sep-05-2023, 04:03 PM
Last Post: deanhystad
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,164 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Sending Whatsapp Message in the text file ebincharles869 9 3,650 Jun-21-2022, 04:26 PM
Last Post: snippsat
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,741 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  I get attachment paperclip on email without any attachments monika_v 5 2,058 Mar-19-2022, 10:20 PM
Last Post: cosmarchy

Forum Jump:

User Panel Messages

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