Note:- I have checked the question and answer of this post and I have already added default_from_email in my settings as described below. Now, in my contact form I want to receive and email from the users who are trying to contact me.
Hi, I have a blog built in Django which uses Zoho mail to send activation and password reset email. To implement the same, I have added the following code in my settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = '<myadmin emailaddress>'
EMAIL_HOST_PASSWORD = '<myadmin password>'
DEFAULT_FROM_EMAIL = '<myadmin email address'
It works flawlessly and the user signing up is getting the activation email and reset emails.
Now, while creating the contact page for my website, I have added a contact form where the user is required to add his name, email and message.
The contact form is like this
class ContactForm(forms.Form):
name = forms.CharField(max_length=100)
email = forms.EmailField()
message = forms.CharField(widget=forms.Textarea)
The view for the same is :-
def contact_us(request):
if request.method == "POST":
form = ContactForm(request.POST)
if form.is_valid():
sender_name = form.cleaned_data['name']
sender_email = form.cleaned_data['email']
message = f"{sender_name} has sent you a new message:\n\n{form.cleaned_data['message']}"
send_mail('New Enquiry', message, sender_email, ['[email protected]'])
return HttpResponse('Thanks for contacting us!')
else:
form = ContactForm()
return render(request, 'accounts/contactus.html', {'form': form})
Now, when I am adding the email, message and name, I am getting the following error:-
SMTPDataError at /contact/
(553, b'Relaying disallowed as [email protected]')