-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update "Sending e-mail" docs to work with Python 3 #93
Comments
Okay, I got it working. When adding attachments, I also needed to add the second line as below: msg.set_payload(contents)
# Encode the payload using Base64. This line is from here:
# https://docs.python.org/3/library/email-examples.html
encoders.encode_base64(msg) This also needs to be updated in the docs for Python (see here). I'm not sure how the docs should handle documenting both Python 2 and Python 3. |
FYI I encountered similar issue and my quick hack is: |
Thanks @cjerdonek! |
thankyou @cjerdonek for your research ! |
Saved my hind quarters, thank you. I hope they take this up a notch (soon?). |
Awesome fix @cjerdonek, thanks a lot |
@cjerdonek You, are A SAVIOR!!!! Thank you so much! |
@cjerdonek Thank you so much! |
Just in case still faces an issue like me, here is my code. with open(file, 'rb') as pdf_file:
pdf = MIMEBase('application', "pdf")
pdf.set_payload(pdf_file.read())
encoders.encode_base64(pdf)
pdf.add_header('Content-Disposition', 'attachment', filename=os.path.basename(file))
message.attach(pdf)
return {'raw': base64.urlsafe_b64encode(message.as_bytes()).decode()} |
Wow, 2 years passed since Apr 20, 2015. But I'm still running into the same issue. |
Still same issue in 2017! Thanks @cjerdonek |
Still same issue in October 2017! here is a full working python 3.6 script for sending messages with attatchments (you just need to fill out the arguments for create_message_with_attatchment): I spent 2 hours to make it work, quite sad that they don't update their documentation. |
Google should update its documentation. |
Still same issue in April 2018!! @LuaBR your script is the first fully working example I see. sadly this issue has taken me nearly one day... |
@LuaBR You are my hero. I spent the whole bloody day trying to fix Google's code. It's a shame Google doesn't care about developers. |
I apologize that this has slipped under the radar so long. I'm really glad that @LuaBR's solution has been able to help those who've found this issue. Unfortunately, the people who maintain this library do not maintain those samples. The good news is that we're all at the same company, so I've filed a bug internally with them to update their documentation and samples (internal issue number 78191393)- and I'll happily help them do so. I'm going to close this issue as there isn't anything actionable for this library. I will comment here when the internal issue about the documentation is addressed. Thanks, everyone. |
Just reporting that this issue still exists as of July 2018, spent hours trying to fix something that doesn't really need more than 3 minutes of docs corrections to help the users and developers who rely on you... isn't it ridiculous that the people writing the documentation are not the same people maintaining the library with all it's changes and issues? This is again the same feeling I had developing in "Google Apps script"... it seems that both here and there you guys don't talk to each other and just file "internal bug reports" that no one ever attends to. THANK YOU @LuaBR for your solution! |
This is a temporary workaround for googleapis#93, though may end up being the final fix. I did some test cleanup while I was here, switching to `mock`.
Just reporting ,this is still happening as of 21 Oct 2019. |
Still now the same error. I mean, ohh come on google update your docs. |
Apologies for all the frustration caused by this. I've pinged the internal bug originally filed by Thea. Thank you for your patience. |
Still an issue in February, 2020. I see this issue is closed which is fine. Where can we keep up-to-date on the progress of the documentation issue? On the bright side, my client was only billed about 6 hours for this frustration, not a whole day. That's a win, right!? |
Coming somewhat late to the party, but here's my solution if it helps others: |
@PFython that helped a ton, thx for your most recent post!! |
Has anyone figured out how to reply to a given thread using thread id? |
@karman1102 I'm not sure what all needs to be in line for e-mails to group together, but I don't think it has anything to do with the e-mail itself. Gmail is grouping them on the recipient's side. I was always under the impression that as long as the subject was exactly the same (minus "Re: ", "Fwd: ", etc.), Gmail would group them (unless there's no subject). I've had this happen to me when it's not desired (accidentally-matching subjects like "Invoice"). That stack exchange question and answer certainly seem to suggest a "thread id" 🤷♂️ . |
@fw-aaron The use of thread id and subject had been mentioned in the official documentation as well. I wonder if anyone has accomplished the 'grouping' together of mails on the recipient's side. What I wish to accomplish is - replying from Gmail API to a mail such that it appears as a 'replied-to' mail on the recipient's end. That is, grouped together |
Same issue in May 2021! |
Yes, I faced the same issue in May 2021! |
The documentation for sending e-mails doesn't seem to work when using Python 3. Also, I can't seem to get e-mail sending working with Python 3 when sending binary (PDF) attachments. The code I'm using worked with Python 2. Details are below.
The Gmail REST API documentation for sending e-mail says to do the following:
However, this code results in the following error:
Changing
as_string()
in the above toas_bytes()
:results in the following error:
If I add
raw = raw.decode()
to ensure thatraw
is a string in Python 3 as opposed to bytes, then the e-mail does get sent. However, the PDF attachment now seems to be corrupted:The text was updated successfully, but these errors were encountered: