Sending Mail from Google App Engine - google-app-engine

I am trying to send an email from google app engine using the python 2.7 library but I keep getting Unauthorized sender in the logs. I have tried my gmail account I created the application with as the sender, I registered another gmail address as a developer and tried that but still get Unauthorized sender. I am not sure if it matters but I do have a domain name registered to this application.
Here is the code I am trying:
message = mail.EmailMessage()
message.sender = "ron.....#gmail.com"
message.subject = "Inquiry"
message.to = "ron.....#gmail.com"
message.body = "Please work"
message.send()
I have looked at other articles to no avail.
Google Appengine sending emails: [Error] unauthorized sender
InvalidSenderError: Unauthorized sender (Google App Engine)

from google.appengine.api import mail
mail.send_mail(sender="stackoverflow.com Hossam <Hossam#stackoverflow.com>",
to="rsnyder <rsnyder#stackoverflow.com>",
subject="How to send an e-mail using google app engine",
body="""
Dear rsnyder:
This example shows how to send an e-mail using google app engine
Please let me know if this is what you want.
Best regards,
""")
EDIT:
Note that sender must be an administrator of the application, so in case that you are not and administrator, follow these steps from the post google app engine: how to add adminstrator account

I found the issue. It was the wrong version of the code. I switched to a version 2 and didn't realize I had to activate it.

Related

Gmail API - Wrong exception fired when user's Gmail account is disabled

I'm working on a C# project that use Gmail API in single-user mode to retrieve user's mail. The application is working nicely.
Recently, we got a strange behavior from this API. When the user hasn't a #gmail account with Gmail disabled and try to use our product, for some we got a "Bad Request 400" with "Mail service not enabled" exception and for other users, we got "Bad Request 400" with "failedPrecondition" exception.
The users are on the same domain name. I searched through Gmail API documentation and I found nothing that can explain this.
Our thoughts are that maybe some users have different settings in their Google account that can cause the "general" "failedPrecondition".
Any advice?
Thanks

Mail GAE not sending but

I have a problem sending mail with JavaMail Service in GAE.
I did all the code in the documentation, i debug it online and it work fine, and it count the mail sended in the quota section the problem is, i didn't receive anything, and also checked with the account sender and it's the same there isn't any trace of mail sended. I tried this for some mails address and it's not working too.
Anyone had this problem yet? A solution to this?
The problem is that the mail sended as SPAM on gmail account.
Read doc: https://cloud.google.com/appengine/docs/java/mail/#Java_Authenticating_mail_DKIM
The email used to send the mails must be a member of the application. It can be the problem... It was with me.
https://cloud.google.com/appengine/docs/python/mail/
The link is about python but for sure that the same email rules apply to Java.
For security purposes, the sender address of a message must be one of the >following:
The Gmail or Google Apps Account of the user who is currently signed in
Any email address of the form anything#appname.appspotmail.com or >anything#appalias.appspotmail.com
Any email address listed in Email API Authorized Senders found in the App >Engine Settings page of the Developers Console

Google Cloud Pubsub authentication error from App Engine

We're having trouble publishing messages to a Google Cloud PubSub topic on Google AppEngine. Using the Application Default credentials works perfect locally. But once it's deployed on Google AppEngine it gives the following error:
<HttpError 403 when requesting https://pubsub.googleapis.com/v1/projects/our-project-id/topics/our-topic:publish?alt=json returned "The request cannot be identified with a project. Please pass a valid API key with the request.">
I would assume that it's will use the service account of app engine to access the PubSub API. Here is the code we used to create the credentials.
credentials = GoogleCredentials.get_application_default()
if credentials.create_scoped_required():
credentials = credentials.create_scoped(['https://www.googleapis.com/auth/pubsub'])
http = httplib2.Http()
credentials.authorize(http)
pubsub_service = build('pubsub', 'v1', http=http)
The error is thrown when publishing the actual message to PubSub.
pubsub_service.projects().topics().publish(topic="projects/out-project-id/topics/out-topic", body = { 'messages' : [ { 'data': base64.b64encode(request.get_data()) }]}).execute()
Not that the same flow works doing API call's to "BigQuery", so it's not a general Google API problem. It seems to be specific to PubSub...
It's a rare case of the service account without project id embedded in it. We fixed your service account and you should be good to go now. Sorry for the trouble.

What is the subscription stanza should be sent from my .net app to get XMPP notification from GAE app

Quick question: What is the subscripiton stanza should sent from my .net app to GAE app.
Background is :
I want to have a google app engine app act as a Web end point which receives notifications from Google Mirror SDK by JSON over HTTP and relays notification back to the subscribed XMPP clients. From Google App Engine, it sends invitation and sends messages that can be seen from Google Talk client on my windows system. I want to make my .net app similar to Google talk client, i'm trying with agXMPP library, after sending subscription stanza, it throws exception and disconnects the connection.
What is the correct subscription stanza i should send?
I'm sending:
<iq to="user_name#gmail.com" id="agsXMPP_1" type="set">
<subscribe xmlns="google:push">
<item from="test_appid.appspot.com" channel="test_appid.appspot.com" />
</subscribe>
</iq>
Thanks
I tried myself and figure it out. Just accept the invitation and send IQ object like this after opening the connection:
IQ iq = new IQ();
Jid jid = new Jid("app-id#appspot.com");
iq.To = jid;
iq.From = _bareJid;
XmppCon.Send(iq);
It worked.

How can my appengine app send mail using the senderid of domain that installed the app

Say I have an appengine app called foo at foo.appspot.com and my email i.e. adminfoo(at)gmail.com is it's adminstrator.
Now, I want to sell this service to blah.com. blah.com has a google app account and 'adds' the foo application and sets the url http://foo.blah.com to point to it.
Now, using the new namespace manager, I carve out separate data for blah.com but when blah.com wants to send out email currently the only way it is possible is either
sender is admin i.e. adminfoo (at) gmail.com
or foo.appspot.com has to add someone(#)blah.com as a developer
Is there any other way? What happens if one has 1,000's of customers ?
Also, the docs state that the email sender can be 'the currently logged in user'. So, if someone(at)blah.com were to 'login' using the google login and 'stay logged in to the app' than can the app send email on behalf of someone(at)blah.com with someone(at)blah.com being the sender?
The other way is that your app can send email as anything#appid.appspotmail.com, where 'appid' is its App ID. As you say, you can also send email as the logged in user - but only on requests made by that user - so sending mail as them from the Task Queue is out.
You might want to look into an 3rd party E-Mail provider. We use http://postmarkapp.com/ for our AppEngine projets (via huTools.postmark) and we love it.

Resources