...and BTW, yet another major bug in your code (100% unrelated to either
App Engine or the Gmail API, I believe) comes in the line:

raw= encoders.encode_base64(msg)

which appears to completely disregard a clear note in the Python standard
library documentation --
https://docs.python.org/3/library/email.encoders.html -- stating, and I
quote:

Note that these functions are not meaningful for a multipart message. They
must be applied to individual subparts instead, and will raise a TypeError
<https://docs.python.org/3/library/exceptions.html#TypeError> if passed a
message whose type is multipart.
("these functions" meaning all those in email.encoders). But remember, you
built `msg` as:

msg = MIMEMultipart('alternative')

so it *is* indeed "a multipart message" -- and indeed, your code *does*
raise TypeError, just as the docs say it will, since msg is exactly "a
message whose type is multipart".

(I kept researching the bugs in your code, since it's Saturday anyway, so
I'm on my own time, and my interest in Python is not limited to Google App
Engine -- the third edition of "Python in a Nutshell" is due out in a
month-plus, and in it I do cover the standard library's email package; so,
just checking if I did properly give that warning, as the online docs do
per the above quote, in my condensed coverage of email.encoders).


Alex


On Sat, Mar 4, 2017 at 10:20 AM, Alex Martelli <al...@google.com> wrote:

> On Sat, Mar 4, 2017 at 4:14 AM, Guillaume France <gc.com...@gmail.com>
> wrote:
>
>> I understand that this kind of question bother you, and the people of
>> this group, but as I mention in my email, it does also bother people on the
>> stack. (This question will be seen and down-voted as duplicate.)
>>
>> Since it’s a question about a Google product (Gmail API), the logical way
>> would be to post it in forum own by Google,
>>
>
> The logical way, if the Gmail API was indeed pertinent, might be to post
> in a forum that's about the Gmail API. Why you choose instead to post in a
> forum that's about a different product (Google App Engine) I am still
> unable to understand.
>
> If you had, say, problems with some Fruit of the Loom product, would you
> choose to discuss them in a forum about Dairy Queen, just because Berkshire
> Hathaway owns both?
>
> And I don't see ANY reference to gmail in your code on this thread, either
> -- specifically in the code of function create_message_with_attachment
> which you posted on this thread. It only uses stuff from the email package
> of the standard Python library.
>
> Further, I do not understand why you claim that posting your question to
> stackoverflow would result in it being closed as duplicate. That would
> happen only if the same subject (adding an attachment to a
> multipart/alternate mail, in Python 3) had already been covered, and in
> this case you'd get a pointer to the preexisting question, whose answer
> would also be an answer to your own question. That's part of how
> stackoverflow works -- and I know the site pretty well, having a reputation
> of over half a million over there.
>
>
>
>> since users seeking help are under its responsibility. This Google group
>> seems to be the only one talking about Gmail api.
>>
>
> This group, as it says right at https://groups.google.com/
> forum/#!forum/google-appengine, is "the community forum for users of
> Google App Engine" -- a very different product from Gmail. I believe
> discussions of gmail happen at https://productforums.
> google.com/forum/#!forum/gmail (though I'm not an expert about that) and
> a brief search suggests that discussions specifically about the API parts
> of gmail are no exception. But, again, your function 
> create_message_with_attachment
> does not appear to make any use whatsoever of any part of a gmail API.
>
>
>>
>> The reality is that Google escape from its responsibility by asking users
>> to use stack. But you seem to ignore that G*oogle doesn’t own stack*,
>> and that *stack has not been built to serve as Gmail api discussion**.
>> Stack has its own rules, you can’t ask such question (without losing
>> points).
>>
>
> Generic "discussion" is indeed inappropriate on stackoverflow; specific
> technical questions and answers, on "every question about programming" to
> quote the site itself, are what it's all about. Since you do appear to have
> a specific question about programming, it should be welcome there (once
> appropriately tagged). As I mention, my reputation score there is over half
> a million, so I must not have lost too many points by asking inappropriate
> questions -- which suggests to me that I do know which questions are or are
> not appropriate there.
>
> The fact that neither Google nor any of our main competitors own
> stackoverflow (all of stackexchange is owned by an independent private
> company) makes for an interesting "level playing field" in the specific
> arena of technical questions and answers about programming. stackoverflow,
> as a company, welcomes sponsorship of specific tags by companies interested
> in them -- that's how a tag such as google-app-engine displays the Google
> Cloud Platform (GCP) logo and sponsored links to our documentation, github,
> etc -- and similarly, a tag such as azure (sponsored by Microsoft) displays
> the Azure logo and sponsored links of Microsoft's choosing.
>
>
>>
>>
>> *So asking Gmail API user seeking for help to leave this group might
>> clear your conscience but that’s pretty much all it does.*
>>
>
> Once again, you are factually incorrect (and using italics won't change
> that:-). stackoverflow's well-deserved popularity means that a helpful
> answer given there gains more web visibility than on almost any other
> venue; if you use a search engine to locate answers to popular programming
> questions, you'll notice that pages on stackoverflow.com are frequently
> close to the top of the search results. For example, search for [python
> flatten list of lists] and the top two results are both on
> stackoverflow.com (the second one a duplicate).
>
> Therefore, anybody who wants to help others as broadly as possible will by
> preference do so on stackoverflow.com for appropriate issues (technical Q
> & A to questions that are about programming), so the help will reach as
> many people as feasible. But that of course is only going to work if
> questions that are appropriate for stackoverflow ARE asked there, rather
> than on random unrelated forums. Encouraging appropriate questions to be
> posted to appropriate sites makes the world an (incrementally) better
> place. Through it, according to stackoverflow's own heuristics, I have
> helped over 44 million people with my answers on that site; that's orders
> of magnitude more people than the one who subscribe to any given mailing
> list, including this one. Moreover, if a mailing list about Google App
> Engine welcomed questions that are not about App Engine at all, as you
> appear to believe it should, its readership would soon plummet as readers
> interested in App Engine unsubscribed from the list due to its spamminess.
>
>
>>
>> * Just another  example
>> <http://stackoverflow.com/questions/42541857/error-using-gmail-api-tuto-using-python-3-except-errors-httperror-error>:
>> I did struggle with several points from the code Google that causes an
>> error in python 3 (google don't update its code). I wanted to share one of
>> them on a stack, in order to help other users. It cost me some reputation
>> point for those —so I
>>
>
> stackoverflow.com (except for the new/beta "documentation" slice, which
> I'm not very familiar with) is about specific technical answers to specific
> technical questions about programming. "Sharing to help other users", not
> in response to specific technical questions, is not within this remit,
> despite it being done with the best of intentions.
>
> Asking a specific, precise technical question about programming, as you
> would be doing in this case, is a completely different case.
>
>
>> won’t do it again. (I then set my answer as "wiki", to don’t lose more
>> points)
>>
>> ps: By the way if I deleted the question and posted it again in this
>> group it’s because I could not edit it, the topic was not accurate anymore
>> and misleading (Google should probably learn from what other company is
>> doing, like Microsoft
>>
>
> Google and Microsoft (and others) sponsor chosen tags on Stackoverflow.
> Microsoft also uses third-party site uservoice, e.g https://visualstudio.
> uservoice.com/forums/121579-visual-studio-ide , and so does Google, e.g
> https://google.uservoice.com/forums/249-general . I am sure there are
> many, many other channels which either or both do use or could use (for
> example, this mailing list is one) although at some point you run into the
> problem of "too many channels".
>
>
> Alex
>
>
>>
>> On Sat, Mar 4, 2017 at 12:17 AM, 'Alex Martelli' via Google App Engine <
>> google-appengine@googlegroups.com> wrote:
>>
>>> I would recommend you post this code and question to stackoverflow.com
>>> -- a very popular site regularly visited by many programming experts who
>>> like to answer technical questions (me included, when I have free time).
>>> You may want to just tag the question as python and email, since it's not
>>> really germane to google-app-engine (if you tagged it with the latter
>>> anyway, your question might be avoided by experts on python and email who
>>> are not also expert on App Engine).
>>>
>>>
>>> Alex
>>>
>>>
>>> On Fri, Mar 3, 2017 at 12:19 PM, Guillaume France <gc.com...@gmail.com>
>>> wrote:
>>>
>>>>
>>>> Thanks a lot Alex, you are right the from email import encoders was
>>>> missing. Now it sends the email but without the file attached to it.
>>>>
>>>> Any idea what could go wrong with this function? (I corrected other
>>>> things on it, it's the result of patchwork of code I took from several
>>>> places)
>>>>
>>>>
>>>> def create_message_with_attachment(sender, to, subject, msgHtml,
>>>> msgPlain):
>>>>
>>>>  # Create message container - the correct MIME type is
>>>> multipart/alternative.
>>>>  msg = MIMEMultipart('alternative')
>>>>  msg['To'] = to
>>>>  msg['From'] = sender
>>>>  msg['Subject'] = subject
>>>>
>>>>  # Record the MIME types of both parts - text/plain and text/html
>>>>  part1 = MIMEText(msgPlain, 'plain')
>>>>  part2 = MIMEText(msgHtml, 'html')
>>>>
>>>>  # create .txt attachment
>>>>  filename=r"C:\Users\xxx\Desktop\test_Attachment.txt"
>>>>  fp=open(filename,'rb')
>>>>  att = email.mime.application.MIMEApplication(fp.read(),_subtype="txt")
>>>>  fp.close()
>>>>  att.add_header('Content-Disposition','attachment',filename=filename)
>>>>
>>>>
>>>>  # Attach parts into message container.
>>>>  msg.attach(att)
>>>>  msg.attach(part1)
>>>>  msg.attach(part2)
>>>>
>>>>  # raw = base64.urlsafe_b64encode(msg.as_bytes())
>>>>  raw= encoders.encode_base64(msg)
>>>>  raw = raw.decode()
>>>>  body = {'raw': raw}
>>>>  return body
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Google App Engine" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to google-appengine+unsubscr...@googlegroups.com.
>>>> To post to this group, send email to google-appengine@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/google-appengine.
>>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>>> gid/google-appengine/3017717e-019f-47a8-96ce-4c45723e9d31%40
>>>> googlegroups.com
>>>> <https://groups.google.com/d/msgid/google-appengine/3017717e-019f-47a8-96ce-4c45723e9d31%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>> --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "Google App Engine" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/to
>>> pic/google-appengine/O94qnKnQu-k/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to
>>> google-appengine+unsubscr...@googlegroups.com.
>>> To post to this group, send email to google-appengine@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/google-appengine.
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/google-appengine/CAE46Be-tAdEGj84ExamTXv5HOGptW-CanLpDxY
>>> y8t%3DnTgqmhVw%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/google-appengine/CAE46Be-tAdEGj84ExamTXv5HOGptW-CanLpDxYy8t%3DnTgqmhVw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Google App Engine" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to google-appengine+unsubscr...@googlegroups.com.
>> To post to this group, send email to google-appengine@googlegroups.com.
>> Visit this group at https://groups.google.com/group/google-appengine.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/google-appengine/CA%2BECagPy-nLc0kKpd5ugHJbEoVcmrW7YV_n3
>> OXrkt4eaj_bSMA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/google-appengine/CA%2BECagPy-nLc0kKpd5ugHJbEoVcmrW7YV_n3OXrkt4eaj_bSMA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/CAE46Be-98ZSJ%3DiUY-KOQLcWXhz_cBP%3Dh9DGt_QpE60aWybVZPg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to