I've been trying to let users send email to my personal account via form. At first it was showing me
socket.gaierror: [Errno 11004] getaddrinfo failed
error which I solved by installing and configuring hMailServer in my device. Now when I try to send mail by my friend's email it send email by my own account instead. When I removed MAIL_HOST_USER = 'my_email'
from settings file, it shows
smtplib.SMTPSenderRefused
error as mentioned in title. Any suggestions or related links will be appreciated.
My code is:
settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_PORT = 25
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'my_email'
EMAIL_HOST_PASSWORD = 'my_password'
EMAIL_USE_TLS = True
views.py
class contact(View):
def post(self, request):
form = ContactForm(request.POST)
if form.is_valid():
if send_mail(subject = form.cleaned_data['title'], message = form.cleaned_data['content'], from_email = form.cleaned_data['contact_email'], recipient_list = ['my_email'], fail_silently=False):
return render(request, 'index.html', {'form': form, 'message': 'Message delivered successfully', 'error':'', 'email_sent': 1 })
else:
return render(request, 'index.html', {'form': ContactForm(), 'error': form.errors})