Who is treated as administrator of GAE application? - python

In accordance with GAE quotas, I can send up to 5000 mails to administrator of the app. But who is treated as administrator? The according Permissions page in the Administration section of GAE console has three users defined:
admin#mydomain.com with role Developer
me#gmail.com with role Owner
somebodyelse#gmail.com with role Viewer
Who is app administrator? First two, all of them or just the second one?
There is a similar question, but it doesn't cover email sending part.

Admin emails get sent to all users who are defined in the project permissions, there is no way to be selective.
To send the emails use the AdminEmailMessage class from google.appengine.api.mail, if you use EmailMessage, then they will come off of your 100 free Recipients Emailed quota, rather than the 3,492,979 Admins Emailed quota.
Example:
Include this import at the top of your script:
from google.appengine.api.mail import AdminEmailMessage
Then use this syntax to send the admin emails.
AdminEmailMessage(
sender = "your#adminaccount.com",
subject = "Hello Admin",
body = "A test admin email"
).send()
This will send an email to all users defined in the projects permissions.
They will then come off of your Admins Emailed quota, rather than your Recipients Emailed quota, as they would if you used the EmailMessage class.
You can use any of these fields, apart from to, cc & bcc.

Related

Django allauth: Linking socail regsitered user to an account which has same email

Here is problem: I allowed user to social login with Google and Github. And both of them have a email scope. And it is possible to both of them have same email. In this kind of situations django redirects to another sign up page
I want to connect both users to same account if their emails are same

How can I update the email address using the confirmation code in Django?

I use all the functionalities of dj-rest-auth to register, log in, confirm the email address, change the password, reset the password and many more. Unfortunately, the library does not support changing the email address. I would like the authenticated user to first enter the account password and the new email address. After the successful process of authentication, I would like to send the user a specially generated confirmation code. Only when he enters it, the old email address will be changed to the new one. As far as I know, there is no such functionality in dj-rest-auth. Unfortunately, I also have not found any current solutions or libraries for this purpose anywhere. Did anyone have such a problem and could share his solution here? Thank you in advance.
Though i don't have any solution for what you want accurately but here is a replace.
You can use django all-auth and some email backend to send an email to the new added email to confirm the new email. In the sent email, there will be a confirmation link and the user has to click that to confirm the new email.
After using django all-auth you only have to add an email backend which will help in sending email. Rest will be maintained by all-auth.
e.g,
In your settings.py you can add an SMTP email backend to send email from your selected gmail account.
Add these lines of code to your settings.py;
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = DEFAULT_FROM_EMAIL = 'HOST_EMAIL' #HOST_EMAIL is your email from which you want to send email to the user.
EMAIL_HOST_PASSWORD = 'HOST_PASSWORD' #HOST_PASSWORD is the password of the email you are using as HOST_EMAIL
But after doing all these things, to make it work locally, you need to go to your google account which you are using as HOST_EMAIL. Go to manage google account >> security >> Turn on less secure apps. Then you will be able to send email to the user.
NOTE: If you have 2-factor authentication turned on for your google account, then these steps will not work. That type of account has some different setup.

Azure Python Flask Get Email id of the user logged in

I created the sample Python Flask Webapp by following the below link.
https://learn.microsoft.com/en-us/azure/app-service/containers/quickstart-python?tabs=bash
I also added the AD Authentication for the Flask application by enabling Authentication in the Settings of the App Services. Now the app works only when the user is logged in and cannot access otherwise.
I would want to fetch the email id if the user who is logged in. I tried checking online but unable to find a way to get the email address of the user.
Any help is really appreciated.
App Service passes user claims to your application by using special headers. So you can get user information from the request header. Some example headers include:
X-MS-CLIENT-PRINCIPAL-NAME
X-MS-CLIENT-PRINCIPAL-ID
You can use res.headers to see all the values.
Reference:
Access user claims

Add to django project an e-mail account

I would like to know if there is any way to add an e-mail account into a django project with all its functionalities; send, receive, bin...
And if so where can I find a tutorial or guide to develop it?
You can send emails in Django very easily. The docs says
Although Python makes sending email relatively easy via the smtplib module, Django provides a couple of light wrappers over it. These wrappers are provided to make sending email extra quick, to make it easy to test email sending during development, and to provide support for platforms that can’t use SMTP.
In two lines:
from django.core.mail import send_mail
send_mail(
'Subject here',
'Here is the message.',
'from#example.com',
['to#example.com'],
fail_silently=False,
)
You can also check this tutorial by Vitor Freitas.
You also need to check https://github.com/anymail/django-anymail which integrates several transactional email service providers (ESPs) into Django, with a consistent API that lets you use ESP-added features without locking your code to a particular ESP.
As Ahmed mentioned yet, that is the way you would send an email. The settings for sending emails are set in your settings.py.
For example:
EMAIL_HOST_USER = 'info#smith.de'
EMAIL_HOST_PASSWORD = '1234' -- you should read the password from a file
EMAIL_USE_SSL = True
EMAIL_HOST = 'smtp.server.de'
EMAIL_PORT = 465
Then you can send your emails like Ahmed mentioned. Django uses the information provided in your settings.py to send emails.

Django Send emails to all users in the database table

I have started django building my first app tutorials, i have to send email to all my users store in the database table on some special Ocations. i have searched on google and found many apis but found it very hard to configure with my app.
here is my model.py
class Users(models.Model):
UserID = models.IntegerField(verbose_name='User ID',max_length=255,primary_key=True)
UserName = models.CharField(verbose_name='User Name',max_length=254,null=True,blank=True)
Email = models.EmailField(verbose_name='Email',max_length=254,null=True,blank=True)
Phone = models.CharField(verbose_name='Phone Number',max_length=254,null=True,blank=True)
i want to have a function here which should get all users one-by-one and send email also tells the status weather the email has been sent or not.
battery's answer is ok, but i would do this way:
recievers = []
for user in Users.objects.all():
recievers.append(user.email)
send_mail(subject, message, from_email, recievers)
this way, you will open only once connection to mail server rather than opening for each email.
Sending email is very simple.
For your Users model this would be:
for user in Users.objects.all():
send_mail(subject, message, from_email,
user.Email)
Checkout Django's Documentation on send emails for more details.
Would be useful if you mention what problem you are facing if you've tried this.
Also note, IntegerField does not have a max_length argument.
for user in Users.objects.all():
send_mail(subject, message, from_email,
user.Email)
This is the best solutions and it works well

Categories

Resources