(550, b'Incorrect sender header (LOCAL)')












0















I try to build contact email form in django using send_mail() function. It works fine in test environment but not in production. On submitting the form I get Server Error (500) in the browser. I receive django error reporting email with the below:



Exception Type: SMTPDataError
Exception Value: (550, b'Incorrect sender header (LOCAL)')



In settings I am using same email address for error reporting and for email form so it works in one case but not in the other. What does the above error mean? Any idea how to fix it?



kontakt.html



<form method="post">
{% csrf_token %}
{{ form.non_field_errors }}
<div class="fieldWrapper">
{{ form.from_email.errors }}
<label for="{{ form.from_email.id_for_label }}">Email:</label><br/>
{{ form.from_email }}
</div>
<div class="fieldWrapper">
{{ form.subject.errors }}
<label for="{{ form.subject.id_for_label }}">Subject:</label><br/>
{{ form.subject }}
</div>
<div class="fieldWrapper">
{{ form.message.errors }}
<label for="{{ form.message.id_for_label }}">Message:</label><br/>
{{ form.message }}
</div>
<div class="form-actions">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</form>


views.py



from django.shortcuts import render, redirect
from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponse, HttpResponseRedirect
from userform.forms import ContactForm

def kontakt(request):
if request.method == 'GET':
form = ContactForm()
else:
form = ContactForm(request.POST)
if form.is_valid():
subject = form.cleaned_data['subject']
from_email = form.cleaned_data['from_email']
message = form.cleaned_data['message']
try:
send_mail(subject, message, from_email, ['admin@example.com'])
except BadHeaderError:
return HttpResponse('Invalid header found.')
return redirect('thanks')
return render(request, "kontakt.html", {'form': form})


def thanks(request):
return HttpResponse('Message sent')


forms.py



from django import forms


class ContactForm(forms.Form):
from_email = forms.EmailField(required=True)
subject = forms.CharField(required=True)
message = forms.CharField(widget=forms.Textarea)


urls.py



from django.conf.urls import url
from userform import views

urlpatterns = [
...
url(r'^kontakt/', views.kontakt, name='kontakt'),
url(r'^thanks/$', views.thanks, name='thanks'),
]


settings.py



EMAIL_HOST = 'smtp.example.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'test@example.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

SERVER_EMAIL = 'test@example.com'
ADMINS=[('admin','admin@example.com')]


Traceback



File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/handlers/exception.py" in inner
35. response = get_response(request)

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in _get_response
128. response = self.process_exception_by_middleware(e, request)

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in _get_response
126. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/pdudko/apps/userform/views.py" in kontakt
88. send_mail(subject, message, from_email, ['admin@example.com'])

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/mail/__init__.py" in send_mail
60. return mail.send()

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/mail/message.py" in send
294. return self.get_connection(fail_silently).send_messages([self])

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/mail/backends/smtp.py" in send_messages
110. sent = self._send(message)

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/mail/backends/smtp.py" in _send
126. self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='rn'))

File "/usr/lib/python3.4/smtplib.py" in sendmail
800. raise SMTPDataError(code, resp)

Exception Type: SMTPDataError at /kontakt/
Exception Value: (550, b'Incorrect sender header (LOCAL)')









share|improve this question




















  • 1





    You need to show us the code where the error occurs (how you're creating the email message), your settings.py (obfuscating sensitive info obviously) and the full django trace, not just the exception type.

    – dirkgroten
    Nov 21 '18 at 12:43
















0















I try to build contact email form in django using send_mail() function. It works fine in test environment but not in production. On submitting the form I get Server Error (500) in the browser. I receive django error reporting email with the below:



Exception Type: SMTPDataError
Exception Value: (550, b'Incorrect sender header (LOCAL)')



In settings I am using same email address for error reporting and for email form so it works in one case but not in the other. What does the above error mean? Any idea how to fix it?



kontakt.html



<form method="post">
{% csrf_token %}
{{ form.non_field_errors }}
<div class="fieldWrapper">
{{ form.from_email.errors }}
<label for="{{ form.from_email.id_for_label }}">Email:</label><br/>
{{ form.from_email }}
</div>
<div class="fieldWrapper">
{{ form.subject.errors }}
<label for="{{ form.subject.id_for_label }}">Subject:</label><br/>
{{ form.subject }}
</div>
<div class="fieldWrapper">
{{ form.message.errors }}
<label for="{{ form.message.id_for_label }}">Message:</label><br/>
{{ form.message }}
</div>
<div class="form-actions">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</form>


views.py



from django.shortcuts import render, redirect
from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponse, HttpResponseRedirect
from userform.forms import ContactForm

def kontakt(request):
if request.method == 'GET':
form = ContactForm()
else:
form = ContactForm(request.POST)
if form.is_valid():
subject = form.cleaned_data['subject']
from_email = form.cleaned_data['from_email']
message = form.cleaned_data['message']
try:
send_mail(subject, message, from_email, ['admin@example.com'])
except BadHeaderError:
return HttpResponse('Invalid header found.')
return redirect('thanks')
return render(request, "kontakt.html", {'form': form})


def thanks(request):
return HttpResponse('Message sent')


forms.py



from django import forms


class ContactForm(forms.Form):
from_email = forms.EmailField(required=True)
subject = forms.CharField(required=True)
message = forms.CharField(widget=forms.Textarea)


urls.py



from django.conf.urls import url
from userform import views

urlpatterns = [
...
url(r'^kontakt/', views.kontakt, name='kontakt'),
url(r'^thanks/$', views.thanks, name='thanks'),
]


settings.py



EMAIL_HOST = 'smtp.example.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'test@example.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

SERVER_EMAIL = 'test@example.com'
ADMINS=[('admin','admin@example.com')]


Traceback



File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/handlers/exception.py" in inner
35. response = get_response(request)

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in _get_response
128. response = self.process_exception_by_middleware(e, request)

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in _get_response
126. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/pdudko/apps/userform/views.py" in kontakt
88. send_mail(subject, message, from_email, ['admin@example.com'])

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/mail/__init__.py" in send_mail
60. return mail.send()

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/mail/message.py" in send
294. return self.get_connection(fail_silently).send_messages([self])

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/mail/backends/smtp.py" in send_messages
110. sent = self._send(message)

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/mail/backends/smtp.py" in _send
126. self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='rn'))

File "/usr/lib/python3.4/smtplib.py" in sendmail
800. raise SMTPDataError(code, resp)

Exception Type: SMTPDataError at /kontakt/
Exception Value: (550, b'Incorrect sender header (LOCAL)')









share|improve this question




















  • 1





    You need to show us the code where the error occurs (how you're creating the email message), your settings.py (obfuscating sensitive info obviously) and the full django trace, not just the exception type.

    – dirkgroten
    Nov 21 '18 at 12:43














0












0








0








I try to build contact email form in django using send_mail() function. It works fine in test environment but not in production. On submitting the form I get Server Error (500) in the browser. I receive django error reporting email with the below:



Exception Type: SMTPDataError
Exception Value: (550, b'Incorrect sender header (LOCAL)')



In settings I am using same email address for error reporting and for email form so it works in one case but not in the other. What does the above error mean? Any idea how to fix it?



kontakt.html



<form method="post">
{% csrf_token %}
{{ form.non_field_errors }}
<div class="fieldWrapper">
{{ form.from_email.errors }}
<label for="{{ form.from_email.id_for_label }}">Email:</label><br/>
{{ form.from_email }}
</div>
<div class="fieldWrapper">
{{ form.subject.errors }}
<label for="{{ form.subject.id_for_label }}">Subject:</label><br/>
{{ form.subject }}
</div>
<div class="fieldWrapper">
{{ form.message.errors }}
<label for="{{ form.message.id_for_label }}">Message:</label><br/>
{{ form.message }}
</div>
<div class="form-actions">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</form>


views.py



from django.shortcuts import render, redirect
from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponse, HttpResponseRedirect
from userform.forms import ContactForm

def kontakt(request):
if request.method == 'GET':
form = ContactForm()
else:
form = ContactForm(request.POST)
if form.is_valid():
subject = form.cleaned_data['subject']
from_email = form.cleaned_data['from_email']
message = form.cleaned_data['message']
try:
send_mail(subject, message, from_email, ['admin@example.com'])
except BadHeaderError:
return HttpResponse('Invalid header found.')
return redirect('thanks')
return render(request, "kontakt.html", {'form': form})


def thanks(request):
return HttpResponse('Message sent')


forms.py



from django import forms


class ContactForm(forms.Form):
from_email = forms.EmailField(required=True)
subject = forms.CharField(required=True)
message = forms.CharField(widget=forms.Textarea)


urls.py



from django.conf.urls import url
from userform import views

urlpatterns = [
...
url(r'^kontakt/', views.kontakt, name='kontakt'),
url(r'^thanks/$', views.thanks, name='thanks'),
]


settings.py



EMAIL_HOST = 'smtp.example.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'test@example.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

SERVER_EMAIL = 'test@example.com'
ADMINS=[('admin','admin@example.com')]


Traceback



File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/handlers/exception.py" in inner
35. response = get_response(request)

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in _get_response
128. response = self.process_exception_by_middleware(e, request)

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in _get_response
126. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/pdudko/apps/userform/views.py" in kontakt
88. send_mail(subject, message, from_email, ['admin@example.com'])

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/mail/__init__.py" in send_mail
60. return mail.send()

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/mail/message.py" in send
294. return self.get_connection(fail_silently).send_messages([self])

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/mail/backends/smtp.py" in send_messages
110. sent = self._send(message)

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/mail/backends/smtp.py" in _send
126. self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='rn'))

File "/usr/lib/python3.4/smtplib.py" in sendmail
800. raise SMTPDataError(code, resp)

Exception Type: SMTPDataError at /kontakt/
Exception Value: (550, b'Incorrect sender header (LOCAL)')









share|improve this question
















I try to build contact email form in django using send_mail() function. It works fine in test environment but not in production. On submitting the form I get Server Error (500) in the browser. I receive django error reporting email with the below:



Exception Type: SMTPDataError
Exception Value: (550, b'Incorrect sender header (LOCAL)')



In settings I am using same email address for error reporting and for email form so it works in one case but not in the other. What does the above error mean? Any idea how to fix it?



kontakt.html



<form method="post">
{% csrf_token %}
{{ form.non_field_errors }}
<div class="fieldWrapper">
{{ form.from_email.errors }}
<label for="{{ form.from_email.id_for_label }}">Email:</label><br/>
{{ form.from_email }}
</div>
<div class="fieldWrapper">
{{ form.subject.errors }}
<label for="{{ form.subject.id_for_label }}">Subject:</label><br/>
{{ form.subject }}
</div>
<div class="fieldWrapper">
{{ form.message.errors }}
<label for="{{ form.message.id_for_label }}">Message:</label><br/>
{{ form.message }}
</div>
<div class="form-actions">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</form>


views.py



from django.shortcuts import render, redirect
from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponse, HttpResponseRedirect
from userform.forms import ContactForm

def kontakt(request):
if request.method == 'GET':
form = ContactForm()
else:
form = ContactForm(request.POST)
if form.is_valid():
subject = form.cleaned_data['subject']
from_email = form.cleaned_data['from_email']
message = form.cleaned_data['message']
try:
send_mail(subject, message, from_email, ['admin@example.com'])
except BadHeaderError:
return HttpResponse('Invalid header found.')
return redirect('thanks')
return render(request, "kontakt.html", {'form': form})


def thanks(request):
return HttpResponse('Message sent')


forms.py



from django import forms


class ContactForm(forms.Form):
from_email = forms.EmailField(required=True)
subject = forms.CharField(required=True)
message = forms.CharField(widget=forms.Textarea)


urls.py



from django.conf.urls import url
from userform import views

urlpatterns = [
...
url(r'^kontakt/', views.kontakt, name='kontakt'),
url(r'^thanks/$', views.thanks, name='thanks'),
]


settings.py



EMAIL_HOST = 'smtp.example.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'test@example.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

SERVER_EMAIL = 'test@example.com'
ADMINS=[('admin','admin@example.com')]


Traceback



File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/handlers/exception.py" in inner
35. response = get_response(request)

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in _get_response
128. response = self.process_exception_by_middleware(e, request)

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/handlers/base.py" in _get_response
126. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/pdudko/apps/userform/views.py" in kontakt
88. send_mail(subject, message, from_email, ['admin@example.com'])

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/mail/__init__.py" in send_mail
60. return mail.send()

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/mail/message.py" in send
294. return self.get_connection(fail_silently).send_messages([self])

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/mail/backends/smtp.py" in send_messages
110. sent = self._send(message)

File "/home/pdudko/venv/lib/python3.4/site-packages/django/core/mail/backends/smtp.py" in _send
126. self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='rn'))

File "/usr/lib/python3.4/smtplib.py" in sendmail
800. raise SMTPDataError(code, resp)

Exception Type: SMTPDataError at /kontakt/
Exception Value: (550, b'Incorrect sender header (LOCAL)')






django forms email server






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 13:47







pawel

















asked Nov 21 '18 at 11:07









pawelpawel

13




13








  • 1





    You need to show us the code where the error occurs (how you're creating the email message), your settings.py (obfuscating sensitive info obviously) and the full django trace, not just the exception type.

    – dirkgroten
    Nov 21 '18 at 12:43














  • 1





    You need to show us the code where the error occurs (how you're creating the email message), your settings.py (obfuscating sensitive info obviously) and the full django trace, not just the exception type.

    – dirkgroten
    Nov 21 '18 at 12:43








1




1





You need to show us the code where the error occurs (how you're creating the email message), your settings.py (obfuscating sensitive info obviously) and the full django trace, not just the exception type.

– dirkgroten
Nov 21 '18 at 12:43





You need to show us the code where the error occurs (how you're creating the email message), your settings.py (obfuscating sensitive info obviously) and the full django trace, not just the exception type.

– dirkgroten
Nov 21 '18 at 12:43












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410799%2f550-bincorrect-sender-header-local%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410799%2f550-bincorrect-sender-header-local%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to send String Array data to Server using php in android

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Is anime1.com a legal site for watching anime?