Email conformation problem

43 views
Skip to first unread message

Ismail Sarenkapic

unread,
May 15, 2017, 8:47:57 AM5/15/17
to Django users
from django.conf import settings
from django.contrib.auth.models import (
BaseUserManager, AbstractBaseUser
)
from django.contrib import messages
from django.core.mail import send_mail
from django.conf import settings
from django.core.validators import RegexValidator
from django.db import models
from django.db.models.signals import post_save
# Create your models here.
from .utils import code_generator

USERNAME_REGEX = '^[a-zA-Z0-9.+-]*$'

class MyUserManager(BaseUserManager):
def create_user(self, username, email, password=None):
"""
Creates and saves a User with the given email, date of
birth and password.
"""
if not email:
raise ValueError('Users must have an email address')

user = self.model(
username = username,
email=self.normalize_email(email),
)

user.set_password(password)
user.save(using=self._db)
return user

def create_superuser(self, username, email, password):
"""
Creates and saves a superuser with the given email, date of
birth and password.
"""
user = self.create_user(
username,
email,
password=password,
)
user.is_admin = True
user.is_staff = True
user.save(using=self._db)
return user


def get_email_field_name(self, email):
email_string = str(self.email)
return email_string

class MyUser(AbstractBaseUser):
username = models.CharField(
max_length=255,
validators=[
RegexValidator(
regex = USERNAME_REGEX,
message = 'Username must be Alpahnumeric or contain any of the following: ". @ + -" ',
code='invalid_username'
)],
unique=True,
)
email = models.EmailField(
verbose_name='email address',
max_length=255,
unique=True,
)
zipcode = models.CharField(max_length=120, default="92660")
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)
is_admin = models.BooleanField(default=False)

objects = MyUserManager()

USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email']

def get_full_name(self):
# The user is identified by their email address
return self.email

def get_short_name(self):
# The user is identified by their email address
return self.email

def __str__(self): # __unicode__ on Python 2
return self.email

def has_perm(self, perm, obj=None):
"Does the user have a specific permission?"
# Simplest possible answer: Yes, always
return True

def has_module_perms(self, app_label):
"Does the user have permissions to view the app `app_label`?"
# Simplest possible answer: Yes, always
return True



# @property
# def is_staff(self):
# "Is the user a member of staff?"
# # Simplest possible answer: All admins are staff
# return self.is_admin



class ActivationProfile(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
key = models.CharField(max_length=120)
expired = models.BooleanField(default=False)

def save(self, *args, **kwargs):
self.key = code_generator()
super(ActivationProfile, self).save(*args, **kwargs)


def post_save_activation_receiver(sender, instance, created, *args, **kwargs):
if created:
#send email
subject = 'Registration'
message = "http://127.0.0.1:8000/activate/{0}".format(instance.key)
from_email = settings.EMAIL_HOST_USER
recipient_list = ['UserEmail']
print(recipient_list)

send_mail(subject, message, from_email, recipient_list,fail_silently=True)

post_save.connect(post_save_activation_receiver, sender=ActivationProfile)




class Profile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL)
city = models.CharField(max_length=120, null=True, blank=True)

def __str__(self):
return str(self.user.username)

def __unicode__(self):
return str(self.user.username)


def post_save_user_model_receiver(sender, instance, created, *args, **kwargs):
if created:
try:
Profile.objects.create(user=instance)
ActivationProfile.objects.create(user=instance)
except:
pass

post_save.connect(post_save_user_model_receiver,sender=settings.AUTH_USER_MODEL)

Hi!I'm trying to make user authentication system, everything is working fine except this email part in my signal: 
The question is how do I set this reception_list to be email that user is going to enter.I don't know how to refer to email field value(because it is other model) ,in this case with is signal.
def post_save_activation_receiver(sender, instance, created, *args, **kwargs):
   
if created:
       
#send email
        subject = 'Registration'
        message = "http://127.0.0.1:8000/activate/{0}".format(instance.key)
        from_email
= settings.EMAIL_HOST_USER
        recipient_list
= ['UserEmail']
       
print(recipient_list)

        send_mail
(subject, message, from_email, recipient_list,fail_silently=True)

post_save
.connect(post_save_activation_receiver, sender=ActivationProfile)

Constantine Covtushenko

unread,
May 17, 2017, 2:21:22 AM5/17/17
to django...@googlegroups.com
Hi, Ismail

Did you try:

instance.user.email?

I hope it should be what you need.

Regards,
Constantine C.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7ff66609-dce4-4ea9-a807-93e37a2ab837%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Sincerely yours,
Constantine C

Ismail Sarenkapic

unread,
May 17, 2017, 2:24:44 AM5/17/17
to Django users, constan...@gmail.com
I already fixed the problem tnx.
but i still dont know why are my emails treated like potential fishing content, can you help me with that?
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Constantine Covtushenko

unread,
May 17, 2017, 2:41:05 AM5/17/17
to django...@googlegroups.com
It is not a Django related question, sorry.
I can just suggest to look in 'SPAM' filters in you mailing agent.

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.
Message has been deleted

Andréas Kühne

unread,
May 17, 2017, 3:54:15 AM5/17/17
to django...@googlegroups.com
Hi,

I think Constantine is probably correct. It's not a specific django problem if your emails are being flagged as fishing emails. The problem is more likely how the emails are being sent AFTER they are sent from django. Django only creates an email based on the properties you use - sender, recipient, subject, text content, html content. What happens with the email after that is not djangos fault or problem. Likely issues could be SPF records (because I'm guessing you are not using the domains default email server for sending your email). 

Even if you add more plugins to your django app - if the SPF records aren't correctly setup, email servers will still mark you email as unsafe.

Regards,

Andréas

2017-05-17 8:52 GMT+02:00 Ismail Sarenkapic <ismai...@gmail.com>:
lol, It is Django related question and can be solved with some of third party libraries like allauth, scoialauth etc. 
Please don't replay to the posts when you don't know what it is about.tnx again



--
Sincerely yours,
Constantine C

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

m712 - Developer

unread,
May 17, 2017, 3:56:56 AM5/17/17
to Ismail Sarenkapic, constan...@gmail.com, Django users

That's a pretty rude way to reply for someone who is asking questions. Many major email providers mark emails from servers without a PTR record to their domains as "spam".

Message has been deleted

Ismail Sarenkapic

unread,
May 17, 2017, 6:12:09 AM5/17/17
to Django users, ismai...@gmail.com, constan...@gmail.com, com...@getbackinthe.kitchen
Ok, so how do I solve this problem of fishing content in my mails?

Constantine Covtushenko

unread,
May 17, 2017, 6:13:58 AM5/17/17
to django...@googlegroups.com
Hi Ismail,

Thank you for your suggestion.
Will get it into consideration for future responds.

Have a nice day to all.

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

For more options, visit https://groups.google.com/d/optout.

James Schneider

unread,
May 17, 2017, 6:33:27 AM5/17/17
to django...@googlegroups.com


On May 16, 2017 11:24 PM, "Ismail Sarenkapic" <ismai...@gmail.com> wrote:
I already fixed the problem tnx.
but i still dont know why are my emails treated like potential fishing content, can you help me with that?

There are potentially dozens of reasons for this. Some may be Django-related, most probably are not.

Ensure that the email being generated by Django is properly formatted with all of the fields necessary (message sender/receiver, envelope sender/receiver, subject, mime type, etc.). All email addresses involved should be valid and reachable from other SMTP servers. If HTML formatting is used for the body, ensure it is valid and complete. If necessary, ensure the language used for the email matches the recipient preferences. Often times particular phrases will trigger phishing filters like "someone hacked your account", so avoid those. From the Django perspective, this is about all you can do.

Otherwise, I'd suggest relaying your messages through a real mail provider (smart host) instead of sending them out directly through a local MTA on your server. The provider for your email service (our rather, the mail provider for your site domain) will already be setup properly (hopefully), including any relevant DNS records (PTR, TXT/SPF, etc.). Contact your mail provider with questions.

Running an SMTP server is difficult due to the volume of SPAM/Phishing messages that are sent out. I would highly recommend that you don't run one yourself due to the ancillary setup required and ongoing maintenance needed. Relaying through a mail company will alleviate many of these problems. 

Many companies use reputation-based filtering systems such as Cisco IronPort. You can check your reputation with them here: 


That may also shed some light on what may need correcting if your domain has a low reputation.

Ultimately, though, the answer in many cases is "you can't" because you have no control over the remote filtering system. In most cases, the user will be informed as to why a message was flagged a certain way. You'll need to retrieve this information from the affected customer and/or their IT department to get a reason, and then address it accordingly. I ran mail servers for several domains for years, and I'll never do it again.

-James


m712 - Developer

unread,
May 17, 2017, 8:04:18 AM5/17/17
to Ismail Sarenkapic, constan...@gmail.com, Django users
Do not respond to everyone with the same question. We see it once you respond to somebody (mail is delivered to every subscriber of this group).
I already gave you a suggestion. It should be pretty easy to search "what is a PTR record" and "how to set PTR record on $server_host" on your favorite search engine. Learn to research a little, please.
Other than that, try what James suggested.

On May 17, 2017 1:12 PM, Ismail Sarenkapic <ismai...@gmail.com> wrote:
>
> Ok, so how do I solve this problem of fishing content in my mails?
>

> On Wednesday, May 17, 2017 at 9:56:56 AM UTC+2, m712 - Developer wrote:
>>
>> That's a pretty rude way to reply for someone who is asking questions. Many major email providers mark emails from servers without a PTR record to their domains as "spam".
>>
>> On May 17, 2017 9:52 AM, Ismail Sarenkapic <ismai...@gmail.com> wrote:
>>>
>>> lol, It is Django related question and can be solved with some of third party libraries like allauth, scoialauth etc. 
>>> Please don't replay to the posts when you don't know what it is about.tnx again
>>>
>>> On Wednesday, May 17, 2017 at 8:41:05 AM UTC+2, Constantine Covtushenko wrote:
>>>>
>>>> It is not a Django related question, sorry.
>>>> I can just suggest to look in 'SPAM' filters in you mailing agent.
>>>>

>>>> On Wed, May 17, 2017 at 9:24 AM, Ismail Sarenkapic <ismai...@gmail.com> wrote:
>>>>>
>>>>> I already fixed the problem tnx.
>>>>> but i still dont know why are my emails treated like potential fishing content, can you help me with that?
>>>>>
>>>>>

Reply all
Reply to author
Forward
0 new messages