html - Email sending in django code is not working -
email sending in django code not working, display error "[errno 10061] no connection made because target machine actively refused it" these views.py
def send_email(request): username = request.post.get('username', '') from_email = request.post.get('from_email', '') message = request.post.get('message', '') if username , message , from_email: try: send_mail(username, from_email, message, ['canonizadocharm@ymail.com']) except badheadererror: homecoming httpresponse('invalid header found.') homecoming httpresponseredirect('/contact/thanks/') else: # in reality we'd utilize form class # proper validation errors. homecoming httpresponse('make sure fields entered , valid.')
these contact.html
<form method="post" action="/send_email/" > {% csrf_token %} name: <input type="text" name="username"><br> email: <input type="text" name="from_email"><br> message: <br> <textarea name="message" rows="10" wrap="hard"> </textarea> <input name="redirect" type="hidden"> <input name="next_url" type="hidden"> <br> <input type="submit" value="send"> <input type="reset" value="clear"> </form>
these urls.py
url(r'^send_email/', views.send_email), url(r'^contact/', views.contact), url(r'^thanks/', views.thanks),
and settings.py
email_host = 'localhost' email_host_user = '' email_host_password = '' email_port = 25 email_use_tls = true
your action
value of form must direct view's url, mailto:canonizadocharm@ymail.com
not valid path on server.
updated:
for example, add together new rule urls.py like,
url(r'^mail/', views.send_mail),
then alter action value mail
.
html django email
No comments:
Post a Comment