Get facebook emails using django - python

I'm using django-socialregistration and facebook python sdk.
This is the code to get friends:
friends = request.facebook.graph.get_connections('me', 'friends')
I can get their name and id but I can't get their email address (not their #facebook.com email).
This is another attempt which also can't get their email.
for friend in friends['data']:
request.facebook.graph.get_object(friend['id'])
How can I get the facebook friends email?

It is possible to get the email of a user connected to your app using Graph. However, when connecting or signing in using Facebook users must explicitly give you permission to use their email address. Since none of the friends gave you permission, their e-mail addresses are off limits. What this means is you can encourage the user to have their friends join as well, and make sure that when they sign up you include a request for their e-mail address.

I think you are not getting the email from friends because this is not even possible to get from Facebook`s Graph API.
Check this out:
Facebook Graph API, how to get users email?

Related

Python Social Auth User without email

There is one problem. I need users` emails to register a new one in my application. In other words, email is required for users. But there are Facebook accounts that do not have an email attached. So, in a result, we get an error.
I see one solution: when we recognized that Facebook returned us data without Facebook, show a form where a user should enter his email, he wants to use in the application. And then we can continue register process. But how to realize this? Actually, I have no idea.
What about you?
Thanks
Python social auth partial pipelines is the feature for that, their purpose is to interact with the user to fetch extra data needed for the authentication, for instance requiring emails, confirming the email address, etc.
Check the example application at https://github.com/python-social-auth/social-examples/blob/master/example-django/example/settings.py#L216, it implements a partial pipeline that requests user email if it's missing from the authentication data.

Gmail API - Get sender name

I want to get the string that the user entered as his sender name when sending emails. I can get this from the message API, however it changes sometimes when e.g. the user sends an email through a service like Google Slides. I need the value the user entered manually when he set up his account. What is the best way to get this value?
You need to use another API endpoint. You need to send GET request to this url: https://www.googleapis.com/gmail/v1/users/MAIN_EMAIL_OF_USER/settings/sendAs/EMAIL_THAT_WILL_BE_USED_FOR_SENDING
If you use python library provided by google you can use this endpoint:
service.users().settings().sendAs().get(userId='MAIN_EMAIL_OF_USER', sendAsEmail='EMAIL_THAT_WILL_BE_USED_FOR_SENDING')
More about sendAs user settings in Gmail API you can find here:
https://developers.google.com/gmail/api/v1/reference/users/settings/sendAs

Obtaining user's email id even if email is not verified

I am working on an application using Django/Python.
I am implementing Twitch Connect and I need email address of the user for my application.
My problem is that if the user has verified email id, i obtain it as apart of the django social auth pipeline in "details" argument.
However, if the user has not verified his/her email, 'email' key does not exist in details.
Is there any way I can ensure that email always flows through?
Thank you!
Twitch does not pass through unverified emails with a user's information. It's a valid API design choice.

How to send an email in GAE on behalf of a yahoo, hotmail, or .edu user?

On GAE, a non-gmail user can create a Google Account using their non-gmail email and log into a google app engine application. However, sending from that email does not appear to work all the time.
For example, suppose foobar#yahoo.com creates a google account and they log in. Then, GAE should be able to send email from foobar#yahoo.com during a user request.
The problem is that this does not appear to work for yahoo email accounts and others. In my experience, only the following users can have email sent on their behalf:
Currently logged in gmail users
Currently logged in users with emails that run on google apps
Administrators
However, you cannot send email on behalf of users with the following email address:
yahoo and hotmail users
.gov or .mil users
most .edu users, although I think some schools use google apps and they work.
If I send from those email addresses, I get the following error:
message.send();
File "/base/python_runtime/python_lib/versions/1/google/appengine/api/mail.py", line 799, in send
raise ERROR_MAP[e.application_error](e.error_detail)
InvalidSenderError: Unauthorized sender
Am I missing something here?
I know there are similar questions out there on this topic but I don't think they nail them.
Your application has no right to originate email from addresses you don't own.
Doing so is called spoofing and there has been a lot of work done in the last 8 years to prevent spoofing: DKIM, SPF...
If you need to send email you need to have your own email address(es)/domain to send the email from for this application and you'll need to handle bounces as well.
Update:
Google Accounts
Google accounts can be created using 3rd party domain email addresses (e.g. hotmail, yahoo, *.edu, etc). There will be an email confirmation step to verify the email address, but there may be no greater relationship than this. The email address is the "username" and there's a password created with Google that has nothing to do with the 3rd party domain.
Google accounts don't have to have a mail service component. You can create a Google account and not have Gmail.
Google email on a 3rd party domain
Google Apps can be run "on" 3rd party domains, this can, but not necessarily include Google email.
Google email could be run on any domain without any other "Apps", they offer email outsourcing which is quite attractive to the Education sector. In this scenario, Google is authoritative for email for that domain.
On behalf of mailing
Google email has the functionality to set up "On Behalf of" emailing. This requires configuration. A confirmation email is sent to the target account. Once created the email is sent using the originating account's email address in the mail envelope, so any delivery status messages (delays, rejections) will be returned to this account. The originating email address will also be in the sender header. The address that you're sending on behalf of will appear in the from header in the messages, but otherwise, with regards to security settings and validation, it's a Google email from Google.
A quick search has returned some tech blog websites that suggest that they are considering retiring this feature in favour of supporting third party SMTP services.
Third party SMTP server
So someone could configure their Google Email account with the SMTP server, username and password of their mail service provider and use it to send email via their Google mail interface through the valid servers of their mail service provider. This email would therefore genuinely "originate" from that domain's infrastructure.
I've not read the documentation for this GAE function to send email. However, I can see that if someone is signed into their Google account and that account has a mail service, then it could be possible to send email from that account using an API.
However, Google will not generate email "From" 3rd party domains for which it has not been assigned authority over. The email would not be valid; it would be "spoofed". It may not comply with a variety of security enhancements, could be used maliciously and would bring them into disrepute.
I hope this makes the situation clearer for you.
If the documentation is lacking in this regard, it could be that those who wrote it, being so familiar with email, might find it hard to imagine someone would think it were possible.
For me it looks like Google has changed something. I've had an application running 1,5 years without problems (and changes) but suddenly on 2011-05-03 sending emails for example on behalf of Yahoo users stopped working.
This change also affected other non-Google (non-developer users).
If foobar#yahoo.com creates a Google account and logs in, you will be able to send on behalf of their Gmail user, but not their Yahoo user. Same for Hotmail. As for .gov, .mil or .edu, there's nothing special about these TLDs. If they are Google Apps domains, you can send from them, otherwise you cannot.
Note, though, that you can specify a Reply-To address when sending mail. This can be any email address whatsoever, so if you use a reply-to address of foobar#yahoo.com on outbound mail and the recipient clicks reply, this should be the address that's populated as the recipient.

Connecting to Google app email servers in Python to send from an alias

I'm looking to send many emails via Python and would like to connect to Google's email servers to send it from my company email address (it's for work). I've got working code for sending the email through the old company email (user#work.com) which is our login, but can't figure out how to send it through the alias (user#betterdomain.com) we use frequently.
Long story short, logging in with my regular Google Apps account won't do and I need to sign in with an alias (nickname) instead. Alternatively, I can sign with the regular account (user#work.com) but send via a different email (user#betterdomain.com).
Working in python and pretty new to programming, but am a good listener! (It's like this question: Google Apps - Send email from a nickname but in Python).
If I understand properly, what you are trying to do is get the Google App Engine send an email on behalf of logged in user, who is using his Google Apps Account name to login. Is it right?
In that case, the mail API for App Engine informs about the mail.send_mail() wherein From: address can be the current user if signed in with Google Accounts. If this is not what you are looking for, some clarification might be required.

Categories