Reputation: 381
I made a contact form, I tested with the mailtrap service and it works I receive the messages well.
But when I put the smpt parameters for a real mail account I have this error message
SMTPRecipientsRefused at /contact/
{'[email protected]': (550, b'relay not permitted: you must be authenticated to send messages')}
the smtp server and the mail account is on the host alwasdata.net, but I tested with an outloock account it's the same thing always this same error. it seems to come from the line in the contact method:
message,
'[email protected]',
['[email protected]'],
fail_silently=False,
in settings.py i have this config
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
DEFAULT_FROM_EMAIL = "[email protected]"
EMAIL_USE_TLS = True
EMAIL_USE_SSL = False
EMAIL_HOST = 'smtp-blablabla.net'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_PORT = 587
in a views.py
def contact(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
subject = "Message d'un visiteur sur votre site"
body = {
'Nom': form.cleaned_data['first_name'],
'Tel': form.cleaned_data['tel'],
'Email': form.cleaned_data['email'],
'Message':form.cleaned_data['message'],
}
message = "\n".join(body.values())
try:
send_mail(
subject,
message,
'[email protected]',
['[email protected]'],
fail_silently=False,
)
except BadHeaderError:
return HttpResponse('Invalid header found.')
return redirect('/')
form = ContactForm()
return render(request,'pages/email_form.html',{'form':form})
the forms.py
from django import forms
class ContactForm(forms.Form):
first_name = forms.CharField(max_length=100, required=True)
tel = forms.CharField(max_length=15, required=True)
email = forms.EmailField(required=False)
message = forms.CharField(widget=forms.Textarea, required=True)
Upvotes: 0
Views: 296
Reputation: 381
I changed a few parameters:
I put all the email addresses on the servers where my site is hosted,
try:
send_mail(
subject,
message,
'[email protected]',
['[email protected]'],
fail_silently=False,
)
and at my host I changed the parameters of the mail server so that it redirects to the email address that I was targeting. Now it's work
Upvotes: 0