I am integrating django_paypal with my django_registration setup for which I have created a custom backend. I can't seem to find in the code where it sends the activation email. Is this located in the backend?
I want to wait and send the activation email until after they have completed a paypal checkout and I receive the IPN notification.
The RegistrationProfile.objects.create_inactive_user manager method has a send_email parameter, which defaults to True.
You just need to set send_email=False when you create a new user.
new_user = RegistrationProfile.objects.create_inactive_user(username, email,
password, site,
send_email=False)
Related
I have my email setup for entire django project and it works fine. When it comes to reset password in the following url:
http://127.0.0.1:8000/rest-auth/password_reset/
and after submitting the email, it throws:
SMTPDataError at /rest-auth/password_reset/
(550, b'The from address does not match a verified Sender Identity. Mail cannot be sent until this error is resolved.
when I digged into the issue I noticed that this view doesn't catch from_email at all:
If I manually enter the email here, everything works fine. Also if I use gmail it works fine.
I am wondering what is gone wrong that email is not read!
That's not a bug, but implemented intentionally in Django.
Django maintains a settings.py parameters termed DEFAULT_FROM_EMAIL, which is applied by default if the from_email you've mentioned is None (in EmailMessage class construction).
Note that the email itself is sent by the PasswordResetForm class (forms.py), and it will only be sent out if the receipt is an active user (implementedin the get_users function).
Im using django_yubin to send mails via its mail queue.
However, there are a few instances where I want to send the mail immediately without putting it on the queue.
For example, when a user registers or resets their password. Or certain admin emails.
I tried using Django's built in email system by
from django.core.mail import send_mail as send_mail_core
and then using the send_mail_core() function.
This didnt work - looks like the send_mail in django.core.mail gets overridden by yubin
Thanks for your help
Why would you even try to use send_mail_core if you can select the mail backend inside of send_mail function
def send_mail(subject, message, from_email, recipient_list,
fail_silently=False, auth_user=None, auth_password=None,
connection=None, html_message=None):
connection: The optional email backend to use to send the mail. If
unspecified, an instance of the default backend will be used. See the
documentation on Email backends for more details.
When django sends an email, it takes from a few milli-seconds to a few seconds depending upon the smtp server. So the problem that i am facing is when django starts sending email it freezes there. The user would have to wait till the mail has been sent. I was wondering if i could simply return the html page and in the background the email could be sent without making the user wait for it.
skeleton is that right before the page is being rendered, email is being sent. So, I want to render the page first and then send the email in the background.
I have done something like this in my project that uses threads:
class EmailThread(Thread):
def __init__(self, myemail):
self.myemail = myemail
Thread.__init__(self)
def run(self):
self.myemail.send()
class MyEmailMessage(EmailMessage):
def send_async(self, fail_silently=False):
thread = EmailThread(self)
thread.start()
# send email
email = MyEmailMessage(...)
email.send_async()
There is also a nice project called django-mailer.
It saves the mails in your database and you send them asynchronously via crontab or celery.
I have to send bulk email in django, the email template will be will be customized and the some data in the template will be coming from db. i twas using django notification but it can only send email to the registered users. I have to send emails to the non-registered users. there will be five email template the user can select any one and the email has to be sent.
For ex. An invitation to the event to the group of non-registered users. user will enter email ids, and will do a bulk send. which django package can i use to achieve the same.
You can use django's default sending multiple email system. From here: https://docs.djangoproject.com/en/dev/topics/email/#sending-multiple-emails
You can try like this:
from django.core import mail
connection = mail.get_connection()
connection.open()
reciever_list= ['aa#bb.cc', 'dd#ee.ff'] #extend this list according to your requirement
email1 = mail.EmailMessage('Hello', 'Body goes here', 'from#example.com',
reciever_list, connection=connection)
email1.send()
connection.close()
For bulk email reference, you can check this so answer: How does one send an email to 10,000 users in Django?
Edit
From this stackoverflow answer, you can send emails with template. If you use django 1.7, html_message can be added as perameter of send_mail(). Details here.
By the way, for mass email handling, django has send_mass_mail() method.
I am creating an inactive user and want to send them email for activating there accounts like the one django-registration send when we create an account.
This is my views.py
user = User.objects.create_user(userName, userMail,userPass)
user.is_active=False
user.save()
You should review the topical guide on sending emails. Basically, you'll just use the components from django.core.mail to send an activation email with all the necessary information after you've created the user instance.
It's important that that email contains further information on how the user is supposed to activate their account. The way django-registration does it is that it has a separate model associated with the User instance that specified a unique identifier which would be used in the activation view to identify which user account is supposed to be activated, i.e. creating a GET request to http://foo/accounts/activate/550e8400-e29b-41d4-a716-446655440000 would activate the user account with the associated UUID.
There are some other intricate details that make django-registration a thorough and well-polished solution, in spite of being a bit dated (i.e. no class-based views), so I second #NCao in suggesting that you take enough time to review the sources from the official repository and ripoff and duplicate all the necessary bits.
Basically after a user signed up, you want to set user.is_active=False.
Then you send an URL with the user's information(for example, id) to the user's email.
When the user click the link, it will trigger an activation function. Within the activation function, it firstly extracts the user's information based on the URL (id). Then you can query the user object by calling user.objects.get(id=id). After that, you can set user.is_active=True and save user.
Here is the code to send email:
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
fromaddr='your email address' #(Gmail here)
username='your user name'
password='your password'
def send_email(toaddr,id):
text = "Hi!\nHow are you?\nHere is the link to activate your
account:\nhttp://127.0.0.1:8000/register_activate/activation/?id=%s" %(id)
part1 = MIMEText(text, 'plain')
msg = MIMEMultipart('alternative')
msg.attach(part1)
subject="Activate your account "
msg="""\From: %s\nTo: %s\nSubject: %s\n\n%s""" % (fromaddr,toaddr,subject,msg.as_string())
#Use gmail's smtp server to send email. However, you need to turn on the setting "lesssecureapps" following this link:
#https://www.google.com/settings/security/lesssecureapps
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(username,password)
server.sendmail(fromaddr,[toaddr],msg)
server.quit()
You may also want to check this out: https://github.com/JunyiJ/django-register-activate
Hope it helps!