Code

#20827 closed Bug (invalid)

Email sending bug

Reported by: ashley.faqihi@… Owned by: nobody
Component: Documentation Version: 1.5
Severity: Normal Keywords: email sending
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In the Preventing header injection section of sending Email, the example below imports send_email and defines a send_email function to call send_email:

from django.core.mail import send_mail, BadHeaderError

def send_email(request):

subject = request.POST.get('subject', )
message = request.POST.get('message',
)
from_email = request.POST.get('from_email', )
if subject and message and from_email:

try:

send_mail(subject, message, from_email, admin@example.com?)

except BadHeaderError:

return HttpResponse('Invalid header found.')

return HttpResponseRedirect('/contact/thanks/')

else:

# In reality we'd use a form class
# to get proper validation errors.
return HttpResponse('Make sure all fields are entered and valid.')

Attachments (0)

Change History (1)

comment:1 Changed 12 months ago by timo

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

The imported function is send_mail (no e).

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.