GAE get info (headers) on an inbound email - python

I'm using python 2.7 on GAE. When a user makes a request via a browser, I can get 'meta details' such as IP, browser type, request time and the user object, if they are logged in.
I have set up GAE to receive emails. What equivalent kind of 'meta details' can I retrieve from an inbound email and how do I get that information?

The InboundEmailMessage class has the most frequently used fields ready for direct access. These are:
subject
sender
to
cc
date
attachments
original
It also include original field that exposes the full meessage as a Python email.message.Message - this allows you access to all the email headers and potentially lots more.

Related

Python email create

i can create with python outlook emails and send them. Im Using
The SenderEmailAddress property is read-only and set on received or sent emails, not composed ones.
The Outlook object model provides two main ways for sending emails from other accounts:
The MailItem.SendUsingAccount property which returns or sets an Account object that represents the account under which the MailItem is to be sent. In that case the other account should be configured in an Outlook profile as well.
The MailItem.SentOnBehalfOfName property which returns or sets a string indicating the display name for the intended sender of the mail message. In that case you need to have all the required permissions to do that on behalf of another person. Valid for Exchange only.
On a general note, no mail server (certainly not Exchange Server) will let you spoof the sender name and address (unless you were given an explicit permisison) for the obvious security reasons.
You can send on behalf of another Exchange user (if you have the permission) by setting the MailItem.SentOnBehalfOfName property. You can also create secondary Exchange / POP3/SMTP / IMAP4/SMTP accounts in Outlook and send through these accounts by setting the MailItem.SendUsingAccount property to an Account object from the Application.Session.Accounts collection.

Sending emails through python

I wish to setup a subscribe form. The user will fill his/her email address and on submit an email should be sent to the provided email address for verification. The verification email will have a link on which the user can click to verify the email address.
This form will be in a website which I plan to host at Bluehost.
I read this tutorial about how it can be done in Python. Following is a snippet from the tutorial
import smtplib
s = smtplib.SMTP(host='your_host_address_here', port=your_port_here)
s.starttls()
s.login(MY_ADDRESS, PASSWORD)
My question is will I able to make this work on Bluehost ?,
My understanding is that host and port can be obtained as described
in this link.
Also,is there any third-party service that allows me create such subscribe form as described above?
While this could technically work, I highly recommend using a third-party service to send the actual emails. These days, the chance of your email getting delivered if it's being sent from a random Bluehost server is quite low due to its low "email sender reputation".
Snippet from this link explaining it:
An email sender reputation is a score that an Internet Service Provider (ISP) assigns to an organization that sends email. It’s a crucial component of your email deliverability. The higher the score, the more likely an ISP will deliver emails to the inboxes of recipients on their network. If the score falls below a certain threshold, the ISP may send messages to recipients’ spam folders or even reject them outright.
Some email sending services include SendGrid or Amazon SES.
If your website is static, then please go for third party service beacuse it will be difficult for you to handle the backend and integration part. So, look for some third party applications to do it for you for example SendPulse
If your website is dynamic, i.e if its having some backend server part as well, then this email sending part can be done easily depending upon which language you are using at backend. Most languages has support for sending emails.

How to change email address of user in web2py using standard auth api with username=True

I recent upgraded web2py and starting using username=True, the form returned via auth/profile no longer contains the user email address.
How can a user change email address under the standard api?
With or without username=True, the email address is not editable via the current Auth API (this was changed about a year ago, presumably for security reasons). For now, you'll have to implement your own email change functionality. For extra security, you might want to require password verification, and maybe send a verification email to the new address (and possibly a notification to the old address upon completion of the change).

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

Categories