Python / Django | How to store sent emails? - python

I was wondering how can I store sent emails
I have a send_email() function in a pre_save() and now I want to store the emails that have been sent so that I can check when an email was sent and if it was sent at all.

I think the easiest way before messing up with middleware or whatever is to simply create a model for your logged emails and add a new record if send was successful.

Another way to look at it: send the mail to your backup email account ex: backup#yourdomain.com. So you can store the email, check if the email is sent or not.
Other than that, having an extra model for logged emails is a way to go.

I would suggest making use of an existing django mail app.
django-mailer may do the trick. It has a message log.
I think it is best not to send email directly from views, your views then won't get blocked if your mail server happens not to be functioning, so that's another reason to use something like this.

Related

Recieving emails from my website through flask?

I have an email form on my webpage where the goal is for users to be able to send my account an email. They give me their email but is there a way to send a message from their email to my email without their password. All i'm seeing online is code to send out emails through flask not recieve. What work arounds do you guys suggest where I can have users send me an email through my website.
I am pretty sure that this is not possible.
Otherwise you would have "access" on their account and could write mails to everyone you want.
A solution would be to save the message in the database and if you need it, you can send the message to you, with all the needed information, by your own mail adresse (like AKA commented).

How can we build a node api which will send mail to users and will also generate otp for accessing my python microservices

Is there a way to write an email API on nodejs so that an email containing unique auto-generated OTP will be sent to the user in order to access my python micro-services?
Nodemailer is a popular module for sending email inside nodejs. You can find all the details on the website.
Alternatively, you can use 3rd party API for handling transactional emails. In my experience, SendGrid does the job and has a neat API that's easy to implement.
As far as OTP goes, you can use whatever you prefer to generate the password, just never use Math.random because it's not secure. In general, this is how I would structure my app:
Generate OTP using generate-password, or however you see fit
Save the OTP hash to the database (you shouldn't store actual passwords to databases)
Send the email with your link using Nodemailer or a 3rd party transactional email provider
Once user does what he's instructed to do, you compare the OTP hash with the hash you have saved in your database, and react accordingly
If you need any code examples or anything else let me know and I'll edit my answer.
Hope this helps :)

How to send custom emails in Django Admin?

I need to send custom emails to users after verifying their applications are correct in django admin.The emails are to be sent to a single user and each message will be different depending on the application of the user.I needed to ask whether this is possible in django admin and if so, how can I do it without hardcoding the message each time I want to send the email?
You can use django signals there you should check that applivation was verified and send email to user. Content for email you can generate from template by rendering it to string and send it as email's body. Content will be depend on context which you put to render

what is the best approach to notify per email the user when an event occurs - django

So lets say that user x sends a message to user y on a website.
User y is notified on the website, but it doesn't get any email about this.
The only thing that I am thinking of to solve this is to stick some code to send out an email to user y after the code where user x sends the message to user y.
def send_msg(request)
#request.user sends message to other_user
#send email to other_user and let him know about his new message
I dont know how good this approach is, in terms of performance.
What are your thoughts? How would you approach this?
For performance, you can use django-mailer. django-mailer provides an email backend that queues emails rather than sending it directly. Emails are then sent by a cron job which you should setup, running manage.py send_mail.
Also, you might want to use django-notification app, it has a nice pattern for notification emails + provides a view for the user to check/uncheck the types of notification he/she wants/doesn't want to get by email.
Creating a post_save signal to send the email after the message has been saved to the model would be one solution. Although for performance an email queue solution would be recommended.

Checking the status of a sent email in django

I have a simple mail sending application which runs in python using Django. After sending an email is there a way to see if the recipient has opened it or is it still un-opened?
if so how can i do it?
The two ways to check that I know of are return receipts and checking to see if an image has been loaded. Neither is very reliable. I think the image one is the more reliable of the two, though.
You could take a pluggable app for confirming a link is being clicked, but instead of putting the link in the email, put an image in the email. This would require changing the confirm_email view to output an image (maybe an empty one).
The above library is for confirming passwords but it ought to work for checking that emails are being read, too.
You can try setting require return receipt flag on the email you are sending. But, a lot of people (I know I do) ignore that return receipt so you will never find out in those cases.
If you are asking for a 100% certain method of finding out if the recipient read his/her email, then the straight answer is: NO, you can't do that.
You have no other way than generate confirm url in your message like most sites registrations do. If person would be glad to register on your website, he will certainly click confirm at his email client of any sort. Otherwise it's a spam/scam email.
There is no way you can do it and know it's a live e-mail for sure...
Besides there are 2 other ways mentioned by my colleagues... But they are based on "unsecure" settings in old email clients rather than sure way... IMHO.

Categories

Resources