So I have a form on my web application in which I am trying to collect feedback from users. The form consists of a subject, email, and the content and I want the emails to be sent to my account. I am having a lot of verification and understanding trouble with this. My code is below and I will further explain my problem afterwards.
Settings.py
EMAIL_HOST_USER
and EMAIL_HOST_PASSWORD
are filled on my app.
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '#'
EMAIL_HOST_PASSWORD = '#'
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
Forms.py
class Contact(forms.Form):
subject = forms.CharField(required=True)
content = forms.CharField(widget=forms.Textarea)
email = forms.EmailField(required=True)
Views.py
def about(request):
if request.method == 'GET':
form = Contact()
else:
form = Contact(request.POST)
if form.is_valid():
subject = form.cleaned_data['subject']
content = form.cleaned_data['content']
email = ['contacttexchange@gmail.com']
#try:
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(settings.EMAIL_HOST_USER, settings.EMAIL_HOST_PASSWORD)
server.sendmail(email, email, content)
server.quit()
print "Successfully sent email"
#except SMTPException:
print "Error: unable to send email"
So I am a little bit confused as to how I can send an e-mail from a users account to mine as I would have to get the user to sign in so currently I am trying to send an e-mail from my account to my account and I was just going to append the users e-mail to the content. However this is not working either.
One, is sending e-mails to myself a stupid way of doing it?
Also, regarding the code problem I keep getting verification errors and google says I should setup two way verification. Is this what I should be doing?
Could someone give me some ideas as to where I should be heading? Thanks.