All the Google searching in the world hasn't answered my question, so hoping someone can help me out.
I have a Django based "Contact Me" webpage, which uses a form and the Django send_mail function.
My app is hosted through Heroku.
When I try to submit an email on my form, the form tries send_mail(subject, message, from_email, ["mypersonal#email.com"]) But I get the following error:
(550, b'The from address does not match a verified Sender Identity.
Mail cannot be sent until this error is resolved. Visit
https://sendgrid.com/docs/for-developers/sending-email/sender-identity/
to see the Sender Identity requirements')
This seems to imply to me that the "from_email" needs to be MY verified email on SendGrid, and not the email of the person trying to contact me?
What am I missing? My goal is to have user submissions be sent to my #gmail.com address
You need to get your 'from email' validated. You can find the documentation on sendgrid it self.
You can create a sender identity by doing a POST request on https://api.sendgrid.com/v3/senders using your API key. You can find more details on sender apis here:
https://sendgrid.com/docs/API_Reference/Web_API_v3/Marketing_Campaigns/sender_identities.html
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).
I have my linkedin scope set as follows:
SOCIAL_AUTH_LINKEDIN_SCOPE = ['r_basicprofile', 'r_emailaddress']
When I try logging in using python social auth then an exception is raised which is defined in my model:
if not email:
raise ValueError('Users must have an email address')
while logging in with facebook and google work fine but not linkedin
The error means it does not have email field in it. I am working on my localhost
It looks like for linkedin we need to specify field selectors in order to get email address and other information from it unlike facebook and google. This is what i was missing:
SOCIAL_AUTH_LINKEDIN_FIELD_SELECTORS = ['email-address']
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!
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)