I was facing a problem from the email functionality of django. Here is a piece of code dealing of registering new user’s account and sending mail to them. Instead of sending mails the account is automatically got created !! Is there anybody other than me facing same problem on the email functionality of django?.. I have done all stuffs like setting less_secure_app=on and etc, but!! nothing is happenning
Can I get a help?
class UserSerializer(serializers.ModelSerializer):
confirm_password = serializers.CharField(read_only=True)
class Meta:
model=User
fields=('username','email','password','confirm_password','first_name','last_name')
validators = [
UniqueTogetherValidator(
queryset=User.objects.all(),
fields=['username','email','password']
)
]
def register(self, validated_data):
if validated_data['password'] != validated_data['confirm_password']:
raise serializers.ValidationError({"Message":"Passwords Do not Match!!"})
else:
try:
user_obj=User.objects.create_user(
username=validated_data['username'],
email=validated_data['email'],
password=validated_data['password']
)
user_obj.first_name=validated_data['first_name'],
user_obj.last_name=validated_data['last_name']
user_obj.save(force_insert=True)
if self.log_user_in(validated_data=validated_data) == 1:
subject="Authetication for the course mail"
message="If you receive this mail, that means you have succesfully autheticated and logged in in the account also"
user_obj.email_user(subject=subject,message=message,from_email=EMAIL_HOST_USER)
return user_obj
except Exception as error:
raise serializers.ValidationError({"Message":error})
def log_user_in(self,validated_data):
user_obj=authenticate(username=validated_data['username'],password=validated_data['password'])
if user_obj:
login(user=user_obj)
return 1
else:
return 0
I have attached the piece of code here , to check is there any fault within it!!