Django registration email never arrives - django

I am using django registration to handle um... registration on a site I'm building. I'm running on ubuntu and I've installed postfix and dovecot and maybe some other email apps that I don't fully understand (I used these instructions).
So now I'm pretty sure the postfix server is working. On the system shell I can do:
$ mail -s 'test' pete#example.com
and I get an email 30 nano seconds later. Similarly, in the django shell I can issue:
>>> send_mail('Subject here', 'Here is the message.', 'service#example.com',['pete#example.com'],fail_silently=False)
and I get another email. But, the registration app still never seems to get an email out. I'm at a loss for where to start debugging this, so any advice would be greatly appreciated.
PS: i've completed all the django registration required templates

Did you check if you application sends the mail correctly using python's DebuggingServer? See my answer to another question for some details.
Alternatively you could try Django's ConsoleBackend for debugging the sending of mails.
Additionally you could try sending mails using your mail provider.

Related

Magento 2 not sending forgot password emails, All other emails are fine

I am using magento 2.3.5 on Ubuntu 18. Installed postfix and its already working for other order emails. Only the forgot password emails are not getting sent.
I already have installed Mageplaza SMTP and Postfix.
When customer hits submit he only sees message as "If there is an account associated with mail#mail.com you will receive an email with a link to reset your password." But there is no email received.
I was able to resolve this. In case someone needs answer. SO this was an issue with the custom theme template. When I revert it to the default theme then it started working. Then I re-code the custom theme template and it started working.

Strange behaviour with e-mails between Django and Google

I have configured my Django settings to send an e-mail using gmail (for password reset)
However, I'm facing a strange behaviour from Google:
Locally, it works fine, when I use my Django app and I get the report that an email has been sent;
Deployed on DigitalOcean, using the shell, it works fine:
>>> from django.core.mail import send_mail
>>> send_mail("Objet3", "Message body", "from.eg#gmail.com",['to.eg#gmail.com'], fail_silently=False)
1
However, when using the deployed app, I always get a Server Error 500, which is reported as such by Sentry:
SMTPSenderRefused: (530, b'5.7.0 Authentication Required. Learn more at\n5.7.0 https://support.google.com/mail/?p=WantAuthError f6sm10267338edk.13 - gsmtp', 'webmaster#localhost')
It's really puzzling, as at Gmail:
I have decreased the level of security,
I have created an App pass and implemented it...
Does anyone have an idea, where it may come from ?
Google does not want to be an email provider like this so they've made it increasingly difficult. Look into a provider such as sendgrid, mailgun, or others.
Finally SendGrid was a reasonable and practical solution, as I could configure it to :
send e-mails with my own domain name,
certify the e-mail so it doesn't fall into the spams
and they have a plan for free, absolutely useful in development phase.
Thank you Schillingt for your piece of advice.

Django mail failed to send mail to icloud mail id

I used the below code
from django.core.mail import EmailMessage
email = EmailMessage('Hello', 'World', to=['user#gmail.com'])
email.send()
the message is sent when I used any other mail except icloud, the code says the message has been sent but I didn't receive any message.
Is this Django issue or some policies of icloud is blocking it?
If it works with other mails, than it's most likely an ICloud thing.
Gmail for example considers the SMPT Api as less secure than their G-Mail Api. In order be able to use it you need to grant access for less secure apps maybe there's a similar thing in ICloud.
Stupid question: Have you looked in your spam folder?

One-Time User Authentication with SMS Using Django and Twilio

I am writing a back-end in Django for a mobile app I am creating. I need to authenticate a user the first time they open the mobile app through SMS to verify it is a real person. What needs to happen is the following: user enters phone number in app, server then sends SMS message to user with authentication code, user then enters authentication code in app and server verifies that the code they entered in the app is the same one they received through SMS.
I need to use Twilio with my Django project. I just need to know what would be the best way to go about this? The front-end side of this (the mobile app) is not what I am asking about, I am asking about the code on the back-end that should be implemented. I am struggling to find up to date documentation for django-twilio integration that could do this.
Twilio evangelist and maintainer of django-twilio here.
What you're looking to build is something very easy to do, I can outline the steps for you here:
Create a Django model that stores a user's number and a generated passcode
When a new user is created, take their number and SMS them the code using the Twilio REST API
When they enter the passcode you sent them, cross reference it with the one stored in the database.
If the number is right: verify them, if not, tell them it is wrong and offer to send them an SMS again.
You can use django-passcode as an app in your project.
It exposes APIs to "register" a mobile number and "verify" through SMS based passcode. It uses mobile number and device id pair as unique. It also generates and returns a token for future authorization requests from mobile app. You can use Twilio or any other SMS api to send sms.
https://github.com/sgurminder/django-passcode
I appreciate your feedback for django-passcode
Disclaimer: I'm the maintainer of Django-phone-verify
What you're looking to accomplish is very easy with django-phone-verify app. It comes with Twilio already integrated and few endpoints which you can extend as per your use case.
This package aims at verifying if a phone number requested by a particular client belongs to them. It also takes care of ensuring that the same device provides the verification of passcode which intially requested a passcode to be sent, saving you a few hours of work.
This package also doesn't messes up with your current user model at all. You're free to use this package exactly for one thing: verifying phone numbers. Whether you do it for users, companies, etc. depends on your use-case.
It follows Unix philosphy of Do one thing; do it well
Installation
pip install django-phone-verify
Configuration
Add app to INSTALLED_APPS:
# In settings.py:
INSTALLED_APPS = [
...
'phone_verify',
]
Add settings in your settings.py file:
# Settings for phone_verify
PHONE_VERIFICATION = {
'BACKEND': 'phone_verify.backends.twilio.TwilioBackend',
'TWILIO_SANDBOX_TOKEN':'123456',
'OPTIONS': {
'SID': 'fake',
'SECRET': 'fake',
'FROM': '+14755292729'
},
'TOKEN_LENGTH': 6,
'MESSAGE': 'Welcome to {app}! Please use security code {otp} to proceed.',
'APP_NAME': 'Phone Verify',
'OTP_EXPIRATION_TIME': 3600 # In seconds only
}
Migrate the database:
python manage.py migrate
You get two endpoints (Check API docs), one for registration of phone number and other to verify the passcode. You may override verify endpoint to also create a user as described in the usage docs: https://github.com/CuriousLearner/django-phone-verify/blob/master/docs/usage.rst
Recently I was looking for any library or scheme to sign-in/sign-up users through sms (send sms code and then validate).
Short solution:
Create sms model to generate code for phone number
Send sms with code to client (for example, use twillio)
User got code. And send phone_number + code
Validate it. Response any useful information
Also:
You must to use async code or celery to send sms
Add sms lifetime (for example, 30 seconds)
Clean phone number to valid format
Get or create user by phone number
You may to use this library, for example:
https://github.com/a1k89/django-rest-sms-auth

django send_mail get result

How can i get django send_mail result of email send. I run it local, i do send_mail to my email, and it return True, but letter not sended (because i have not any smtp set). But result is True. How to get real result?
Django uses exceptions to handle email sending problems. The value returned by send_mail is the number of emails that were sent.
If you're not getting an exception, it could be one of a number of things:
You have fail_silently set to True (default is False)
You're using a different email backend (smtp is the default for 1.2+, the only option for earlier versions)
The mail is actually being sent, but something else is wrong (email server, bad email address, spam folders, gmail self-sent mail hiding etc)
Use django-mailer. It puts the emails in the database and uses a cron-jobbed management command to send it out. It will help you track this issue down, improve your app response time, and also make your life easier.
I would also suggest to use exceptions to find out whether email was sent or not.
If you haven't time or option to set up an email server I would suggest to use django+gmail. U can create a 'fake' gmail account (create another one if you already own gmail-acc, it could be 'baned') and use its SMTP as a opportunity to send emails, even if you're working with django's development server (localy). How to is here