Anyone can suggest how to send email with send_mail? It's not workingHow can I represent an 'Enum' in Python?How can I safely create a nested directory?How can I remove a trailing newline in Python?How can I make a time delay in Python?How can you profile a Python script?How can I count the occurrences of a list item?Send email when user creates a directoryFor statement in django templates doesn't workCustomer User Authentication error : AttributeError: Manager isn't available; 'auth.User' has been swapped for 'user_management.CustomUser'How to set dynamic initial values to django modelform field
Soft question: Examples where lack of mathematical rigour cause security breaches?
How does an ordinary object become radioactive?
Should an arbiter claim draw at a K+R vs K+R endgame?
What should the arbiter and what should have I done in this case?
Taxi Services at Didcot
Were Alexander the Great and Hephaestion lovers?
Do any instruments not produce overtones?
Source that a married woman seduced by a “messianic figure” is still permitted to her husband
How to forge a multi-part weapon?
When conversion from Integer to Single may lose precision
Can the poison from Kingsmen be concocted?
Universal hash functions with homomorphic XOR property
How is water heavier than petrol, even though its molecular weight is less than petrol?
What's up with this leaf?
Fixing obscure 8080 emulator bug?
Does an ice chest packed full of frozen food need ice?
Do simulator games use a realistic trajectory to get into orbit?
Why doesn't Adrian Toomes give up Spider-Man's identity?
Should I compare a std::string to "string" or "string"s?
Using "subway" as name for London Underground?
Compiling c files on ubuntu and using the executable on Windows
Logarithm of exponential
How to return a security deposit to a tenant
Are there any important biographies of nobodies?
Anyone can suggest how to send email with send_mail? It's not working
How can I represent an 'Enum' in Python?How can I safely create a nested directory?How can I remove a trailing newline in Python?How can I make a time delay in Python?How can you profile a Python script?How can I count the occurrences of a list item?Send email when user creates a directoryFor statement in django templates doesn't workCustomer User Authentication error : AttributeError: Manager isn't available; 'auth.User' has been swapped for 'user_management.CustomUser'How to set dynamic initial values to django modelform field
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
When user registers is_active is False by default. I want the user get email notification when the admin activates the user. But send_mail is not sending email.
I have created a function in my views.py:
def send_mail(request):
if user.is_active == True:
send_mail(request, subject='subject',
message='message',
from_email='hekevintran_test@webfaction.com',
recipient_list=['recipient@yahoo.com'],
fail_silently=False)
Also I have written down these things in my settings.py:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'ualmaz'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 25
EMAIL_USE_TLS = False
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_FILE_PATH = os.path.join(BASE_DIR, 'apps', 'emails')
Here is my views.py:
from django.shortcuts import render, redirect
from django.contrib import messages
from django.core.mail import send_mail
from django.urls import reverse_lazy
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.views.generic import CreateView, DetailView, ListView, UpdateView, DeleteView
from .forms import UserCreationModelForm, UserUpdateForm, ProfileUpdateForm
from .models import User, Post, Profile
class UserRegistrationView(CreateView):
form_class = UserCreationModelForm
user = User
success_url = reverse_lazy('login')
template_name = 'users/registration.html'
def send_mail(request):
user = User
if user.is_active == True:
send_mail(request, subject='subject',
message='message',
from_email='hekevintran_test@webfaction.com',
recipient_list=['recipient@yahoo.com'],
fail_silently=False)
Here is my User model in models.py:
class User(AbstractUser):
first_name = models.CharField(verbose_name="First name", max_length=255)
last_name = models.CharField(verbose_name="Last name", max_length=255)
country = models.CharField(verbose_name="Country name", max_length=255)
city = models.CharField(verbose_name="City name", max_length=255)
email = models.EmailField(verbose_name="Email", max_length=255)
access_challenge = models.BooleanField(default=False)
is_active = models.BooleanField(default=False)
def __str__(self):
return self.username
Any ideas?
python django
|
show 4 more comments
When user registers is_active is False by default. I want the user get email notification when the admin activates the user. But send_mail is not sending email.
I have created a function in my views.py:
def send_mail(request):
if user.is_active == True:
send_mail(request, subject='subject',
message='message',
from_email='hekevintran_test@webfaction.com',
recipient_list=['recipient@yahoo.com'],
fail_silently=False)
Also I have written down these things in my settings.py:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'ualmaz'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 25
EMAIL_USE_TLS = False
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_FILE_PATH = os.path.join(BASE_DIR, 'apps', 'emails')
Here is my views.py:
from django.shortcuts import render, redirect
from django.contrib import messages
from django.core.mail import send_mail
from django.urls import reverse_lazy
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.views.generic import CreateView, DetailView, ListView, UpdateView, DeleteView
from .forms import UserCreationModelForm, UserUpdateForm, ProfileUpdateForm
from .models import User, Post, Profile
class UserRegistrationView(CreateView):
form_class = UserCreationModelForm
user = User
success_url = reverse_lazy('login')
template_name = 'users/registration.html'
def send_mail(request):
user = User
if user.is_active == True:
send_mail(request, subject='subject',
message='message',
from_email='hekevintran_test@webfaction.com',
recipient_list=['recipient@yahoo.com'],
fail_silently=False)
Here is my User model in models.py:
class User(AbstractUser):
first_name = models.CharField(verbose_name="First name", max_length=255)
last_name = models.CharField(verbose_name="Last name", max_length=255)
country = models.CharField(verbose_name="Country name", max_length=255)
city = models.CharField(verbose_name="City name", max_length=255)
email = models.EmailField(verbose_name="Email", max_length=255)
access_challenge = models.BooleanField(default=False)
is_active = models.BooleanField(default=False)
def __str__(self):
return self.username
Any ideas?
python django
I would be suspicious about this condition:user.is_active == True
– snakecharmerb
Mar 24 at 16:23
But what is supposed to be calling yoursend_mailfunction?
– Daniel Roseman
Mar 24 at 16:23
What error you are getting
– Vikrant Pawar
Mar 24 at 16:27
@DanielRoseman I want to callsend_mailwhen admin activates the registered user.
– Almaz
Mar 24 at 16:30
@snakecharmerb what do you suggest?
– Almaz
Mar 24 at 16:31
|
show 4 more comments
When user registers is_active is False by default. I want the user get email notification when the admin activates the user. But send_mail is not sending email.
I have created a function in my views.py:
def send_mail(request):
if user.is_active == True:
send_mail(request, subject='subject',
message='message',
from_email='hekevintran_test@webfaction.com',
recipient_list=['recipient@yahoo.com'],
fail_silently=False)
Also I have written down these things in my settings.py:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'ualmaz'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 25
EMAIL_USE_TLS = False
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_FILE_PATH = os.path.join(BASE_DIR, 'apps', 'emails')
Here is my views.py:
from django.shortcuts import render, redirect
from django.contrib import messages
from django.core.mail import send_mail
from django.urls import reverse_lazy
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.views.generic import CreateView, DetailView, ListView, UpdateView, DeleteView
from .forms import UserCreationModelForm, UserUpdateForm, ProfileUpdateForm
from .models import User, Post, Profile
class UserRegistrationView(CreateView):
form_class = UserCreationModelForm
user = User
success_url = reverse_lazy('login')
template_name = 'users/registration.html'
def send_mail(request):
user = User
if user.is_active == True:
send_mail(request, subject='subject',
message='message',
from_email='hekevintran_test@webfaction.com',
recipient_list=['recipient@yahoo.com'],
fail_silently=False)
Here is my User model in models.py:
class User(AbstractUser):
first_name = models.CharField(verbose_name="First name", max_length=255)
last_name = models.CharField(verbose_name="Last name", max_length=255)
country = models.CharField(verbose_name="Country name", max_length=255)
city = models.CharField(verbose_name="City name", max_length=255)
email = models.EmailField(verbose_name="Email", max_length=255)
access_challenge = models.BooleanField(default=False)
is_active = models.BooleanField(default=False)
def __str__(self):
return self.username
Any ideas?
python django
When user registers is_active is False by default. I want the user get email notification when the admin activates the user. But send_mail is not sending email.
I have created a function in my views.py:
def send_mail(request):
if user.is_active == True:
send_mail(request, subject='subject',
message='message',
from_email='hekevintran_test@webfaction.com',
recipient_list=['recipient@yahoo.com'],
fail_silently=False)
Also I have written down these things in my settings.py:
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'ualmaz'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 25
EMAIL_USE_TLS = False
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_FILE_PATH = os.path.join(BASE_DIR, 'apps', 'emails')
Here is my views.py:
from django.shortcuts import render, redirect
from django.contrib import messages
from django.core.mail import send_mail
from django.urls import reverse_lazy
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.views.generic import CreateView, DetailView, ListView, UpdateView, DeleteView
from .forms import UserCreationModelForm, UserUpdateForm, ProfileUpdateForm
from .models import User, Post, Profile
class UserRegistrationView(CreateView):
form_class = UserCreationModelForm
user = User
success_url = reverse_lazy('login')
template_name = 'users/registration.html'
def send_mail(request):
user = User
if user.is_active == True:
send_mail(request, subject='subject',
message='message',
from_email='hekevintran_test@webfaction.com',
recipient_list=['recipient@yahoo.com'],
fail_silently=False)
Here is my User model in models.py:
class User(AbstractUser):
first_name = models.CharField(verbose_name="First name", max_length=255)
last_name = models.CharField(verbose_name="Last name", max_length=255)
country = models.CharField(verbose_name="Country name", max_length=255)
city = models.CharField(verbose_name="City name", max_length=255)
email = models.EmailField(verbose_name="Email", max_length=255)
access_challenge = models.BooleanField(default=False)
is_active = models.BooleanField(default=False)
def __str__(self):
return self.username
Any ideas?
python django
python django
asked Mar 24 at 16:21
AlmazAlmaz
609
609
I would be suspicious about this condition:user.is_active == True
– snakecharmerb
Mar 24 at 16:23
But what is supposed to be calling yoursend_mailfunction?
– Daniel Roseman
Mar 24 at 16:23
What error you are getting
– Vikrant Pawar
Mar 24 at 16:27
@DanielRoseman I want to callsend_mailwhen admin activates the registered user.
– Almaz
Mar 24 at 16:30
@snakecharmerb what do you suggest?
– Almaz
Mar 24 at 16:31
|
show 4 more comments
I would be suspicious about this condition:user.is_active == True
– snakecharmerb
Mar 24 at 16:23
But what is supposed to be calling yoursend_mailfunction?
– Daniel Roseman
Mar 24 at 16:23
What error you are getting
– Vikrant Pawar
Mar 24 at 16:27
@DanielRoseman I want to callsend_mailwhen admin activates the registered user.
– Almaz
Mar 24 at 16:30
@snakecharmerb what do you suggest?
– Almaz
Mar 24 at 16:31
I would be suspicious about this condition:
user.is_active == True– snakecharmerb
Mar 24 at 16:23
I would be suspicious about this condition:
user.is_active == True– snakecharmerb
Mar 24 at 16:23
But what is supposed to be calling your
send_mail function?– Daniel Roseman
Mar 24 at 16:23
But what is supposed to be calling your
send_mail function?– Daniel Roseman
Mar 24 at 16:23
What error you are getting
– Vikrant Pawar
Mar 24 at 16:27
What error you are getting
– Vikrant Pawar
Mar 24 at 16:27
@DanielRoseman I want to call
send_mail when admin activates the registered user.– Almaz
Mar 24 at 16:30
@DanielRoseman I want to call
send_mail when admin activates the registered user.– Almaz
Mar 24 at 16:30
@snakecharmerb what do you suggest?
– Almaz
Mar 24 at 16:31
@snakecharmerb what do you suggest?
– Almaz
Mar 24 at 16:31
|
show 4 more comments
1 Answer
1
active
oldest
votes
This is how solved it.
from django.dispatch import receiver
from django.db.models.signals import pre_save, post_save
from django.conf import settings
from django.core.mail import send_mail
#signal used for is_active=False to is_active=True
@receiver(pre_save, sender=User, dispatch_uid='active')
def active(sender, instance, **kwargs):
try:
if instance.is_active and User.objects.filter(pk=instance.pk, is_active=False).exists():
subject = 'Your account is activated'
mesagge = '%s your account is now active' %(instance.first_name)
from_email = settings.EMAIL_HOST_USER
send_mail(subject, mesagge, from_email, [instance.email], fail_silently=False)
except:
print("Something went wrong, please try again.")
#signal to send an email to the admin when a user creates a new account
@receiver(post_save, sender=User, dispatch_uid='register')
def register(sender, instance, **kwargs):
try:
if kwargs.get('created', False):
subject = "Verificatión of the %s 's account" %(instance.username)
mesagge = '%s, %s just registered in locator' %(instance.first_name, instance.last_name)
from_email = settings.EMAIL_HOST_USER
send_mail(subject, mesagge, from_email, [from_email], fail_silently=False)
except:
print("Something went wrong, please try again.")
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55325894%2fanyone-can-suggest-how-to-send-email-with-send-mail-its-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is how solved it.
from django.dispatch import receiver
from django.db.models.signals import pre_save, post_save
from django.conf import settings
from django.core.mail import send_mail
#signal used for is_active=False to is_active=True
@receiver(pre_save, sender=User, dispatch_uid='active')
def active(sender, instance, **kwargs):
try:
if instance.is_active and User.objects.filter(pk=instance.pk, is_active=False).exists():
subject = 'Your account is activated'
mesagge = '%s your account is now active' %(instance.first_name)
from_email = settings.EMAIL_HOST_USER
send_mail(subject, mesagge, from_email, [instance.email], fail_silently=False)
except:
print("Something went wrong, please try again.")
#signal to send an email to the admin when a user creates a new account
@receiver(post_save, sender=User, dispatch_uid='register')
def register(sender, instance, **kwargs):
try:
if kwargs.get('created', False):
subject = "Verificatión of the %s 's account" %(instance.username)
mesagge = '%s, %s just registered in locator' %(instance.first_name, instance.last_name)
from_email = settings.EMAIL_HOST_USER
send_mail(subject, mesagge, from_email, [from_email], fail_silently=False)
except:
print("Something went wrong, please try again.")
add a comment |
This is how solved it.
from django.dispatch import receiver
from django.db.models.signals import pre_save, post_save
from django.conf import settings
from django.core.mail import send_mail
#signal used for is_active=False to is_active=True
@receiver(pre_save, sender=User, dispatch_uid='active')
def active(sender, instance, **kwargs):
try:
if instance.is_active and User.objects.filter(pk=instance.pk, is_active=False).exists():
subject = 'Your account is activated'
mesagge = '%s your account is now active' %(instance.first_name)
from_email = settings.EMAIL_HOST_USER
send_mail(subject, mesagge, from_email, [instance.email], fail_silently=False)
except:
print("Something went wrong, please try again.")
#signal to send an email to the admin when a user creates a new account
@receiver(post_save, sender=User, dispatch_uid='register')
def register(sender, instance, **kwargs):
try:
if kwargs.get('created', False):
subject = "Verificatión of the %s 's account" %(instance.username)
mesagge = '%s, %s just registered in locator' %(instance.first_name, instance.last_name)
from_email = settings.EMAIL_HOST_USER
send_mail(subject, mesagge, from_email, [from_email], fail_silently=False)
except:
print("Something went wrong, please try again.")
add a comment |
This is how solved it.
from django.dispatch import receiver
from django.db.models.signals import pre_save, post_save
from django.conf import settings
from django.core.mail import send_mail
#signal used for is_active=False to is_active=True
@receiver(pre_save, sender=User, dispatch_uid='active')
def active(sender, instance, **kwargs):
try:
if instance.is_active and User.objects.filter(pk=instance.pk, is_active=False).exists():
subject = 'Your account is activated'
mesagge = '%s your account is now active' %(instance.first_name)
from_email = settings.EMAIL_HOST_USER
send_mail(subject, mesagge, from_email, [instance.email], fail_silently=False)
except:
print("Something went wrong, please try again.")
#signal to send an email to the admin when a user creates a new account
@receiver(post_save, sender=User, dispatch_uid='register')
def register(sender, instance, **kwargs):
try:
if kwargs.get('created', False):
subject = "Verificatión of the %s 's account" %(instance.username)
mesagge = '%s, %s just registered in locator' %(instance.first_name, instance.last_name)
from_email = settings.EMAIL_HOST_USER
send_mail(subject, mesagge, from_email, [from_email], fail_silently=False)
except:
print("Something went wrong, please try again.")
This is how solved it.
from django.dispatch import receiver
from django.db.models.signals import pre_save, post_save
from django.conf import settings
from django.core.mail import send_mail
#signal used for is_active=False to is_active=True
@receiver(pre_save, sender=User, dispatch_uid='active')
def active(sender, instance, **kwargs):
try:
if instance.is_active and User.objects.filter(pk=instance.pk, is_active=False).exists():
subject = 'Your account is activated'
mesagge = '%s your account is now active' %(instance.first_name)
from_email = settings.EMAIL_HOST_USER
send_mail(subject, mesagge, from_email, [instance.email], fail_silently=False)
except:
print("Something went wrong, please try again.")
#signal to send an email to the admin when a user creates a new account
@receiver(post_save, sender=User, dispatch_uid='register')
def register(sender, instance, **kwargs):
try:
if kwargs.get('created', False):
subject = "Verificatión of the %s 's account" %(instance.username)
mesagge = '%s, %s just registered in locator' %(instance.first_name, instance.last_name)
from_email = settings.EMAIL_HOST_USER
send_mail(subject, mesagge, from_email, [from_email], fail_silently=False)
except:
print("Something went wrong, please try again.")
answered Mar 26 at 16:03
AlmazAlmaz
609
609
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55325894%2fanyone-can-suggest-how-to-send-email-with-send-mail-its-not-working%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I would be suspicious about this condition:
user.is_active == True– snakecharmerb
Mar 24 at 16:23
But what is supposed to be calling your
send_mailfunction?– Daniel Roseman
Mar 24 at 16:23
What error you are getting
– Vikrant Pawar
Mar 24 at 16:27
@DanielRoseman I want to call
send_mailwhen admin activates the registered user.– Almaz
Mar 24 at 16:30
@snakecharmerb what do you suggest?
– Almaz
Mar 24 at 16:31