Skip to content

Commit

Permalink
contactus page email
Browse files Browse the repository at this point in the history
contactus page email
  • Loading branch information
Anjaneyulu authored and ashwin31 committed Jul 20, 2016
1 parent 8752016 commit 2315fe4
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 6 deletions.
55 changes: 55 additions & 0 deletions django_blog_it/django_blog_it/templates/emails/email_to_admin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ BLOG_TITLE }}</title>
<link href="./Micro Track leaves view to admin_files/css" rel="stylesheet" type="text/css">
</head>
<body style="width:100% !important; margin:0 !important; padding:0 !important; -webkit-text-size-adjust:none; -ms-text-size-adjust:none;font-size:13px; font-family: &#39;Karla&#39;, sans-serif;color: #73879C; background: #e8edf2; ">
<table cellpadding="0" cellspacing="0" border="0" id="backgroundTable" style="height:auto !important; margin:0; padding:0; width:100% !important; font-family: &#39;Karla&#39;, sans-serif;color: #73879C; background: #e8edf2;">
<tbody><tr>
<td>
<table id="contenttable" width="800" align="center" cellpadding="0" cellspacing="0" border="0" style="font-family: &#39;Karla&#39;, sans-serif;color: #73879C; background: #fff; text-align:center !important; margin-top:0 !important; margin-right: auto !important; margin-bottom:0 !important; margin-left: auto !important; border:none; width: 100% !important; max-width:800px !important;border: 1px solid #ddd !important;">
<tbody><tr>
<td>
<table style="width:800px;background:#fff;padding:0;" cellpadding="0" cellspacing="0">
<tbody><tr>
<td style="background: #2A3F54;height:50px;">
<a href="#" style="text-overflow: ellipsis;overflow: hidden;width: 100%;color: #c4d0d9 !important;margin-left: 0 !important;display: block;margin: 0; padding:0;font-weight: bold;text-transform: uppercase;font-size: 18px;text-decoration:none;"><i class="fa fa-line-chart" aria-hidden="true"></i> {{ BLOG_TITLE }}</a>
</td>
</tr>
<tr style="background:#fff;">
<td>
<table style="width:100%; text-align:left;">
<tr>
<td width="6%" style="font-size: 17px;">Name</td> <td>: {{ NAME_OF_USER }}</td>
</tr>
<tr>
<td style="font-size: 17px;">website </td> <td>: {{ WEBSITE_OF_USER }}</td>
</tr>
<tr>
<td colspan="2" style="font-size: 17px;">Description</td>
</tr>
<tr>
<td colspan="2">
{{ USER_DESCRIPTION }}
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="font-weight: bold;padding:12px 0;color: #333 !important;text-decoration: none;background: #e8edf2;">
Yours sincerely, Administration of the service, {{ BLOG_TITLE }}.
</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>


</body></html>
40 changes: 40 additions & 0 deletions django_blog_it/django_blog_it/templates/emails/email_to_user.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> {{ BLOG_TITLE }}</title>
<link href="./Micro Track leaves view to admin_files/css" rel="stylesheet" type="text/css">
</head>
<body style="width:100% !important; margin:0 !important; padding:0 !important; -webkit-text-size-adjust:none; -ms-text-size-adjust:none;font-size:13px; font-family: &#39;Karla&#39;, sans-serif;color: #73879C; background: #e8edf2; ">
<table cellpadding="0" cellspacing="0" border="0" id="backgroundTable" style="height:auto !important; margin:0; padding:0; width:100% !important; font-family: &#39;Karla&#39;, sans-serif;color: #73879C; background: #e8edf2;">
<tbody><tr>
<td>
<table id="contenttable" width="800" align="center" cellpadding="0" cellspacing="0" border="0" style="font-family: &#39;Karla&#39;, sans-serif;color: #73879C; background: #fff; text-align:center !important; margin-top:0 !important; margin-right: auto !important; margin-bottom:0 !important; margin-left: auto !important; border:none; width: 100% !important; max-width:800px !important;border: 1px solid #ddd !important;">
<tbody><tr>
<td>
<table style="width:800px;background:#fff;padding:0;" cellpadding="0" cellspacing="0">
<tbody><tr>
<td style="background: #2A3F54;height:50px;">
<a href="#" style="text-overflow: ellipsis;overflow: hidden;width: 100%;color: #c4d0d9 !important;margin-left: 0 !important;display: block;margin: 0; padding:0;font-weight: bold;text-transform: uppercase;font-size: 18px;text-decoration:none;"><i class="fa fa-line-chart" aria-hidden="true"></i> {{ BLOG_TITLE }}</a>
</td>
</tr>
<tr style="background:#fff;">
<td>
{{ BODY_USER|safe }}
</td>
</tr>
<tr>
<td style="font-weight: bold;padding:12px 0;color: #333 !important;text-decoration: none;background: #e8edf2;">
Yours sincerely, Administration of the service, {{ BLOG_TITLE }}.
</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
</td>
</tr>
</tbody>
</table>
</body>
</html>
7 changes: 3 additions & 4 deletions django_blog_it/django_blog_it/templates/new_base.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{% load staticfiles %}
{% load blog_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Blog - {% block title %}Home{% endblock %}</title>
<title{% blog_title as blogtitle %}{{ blogtitle }} - {% block title %}Home{% endblock %}</title>
{% block description %}
<link rel="canonical" href="{{ request.build_absolute_uri }}"/>
<meta property="og:url" content="{{ request.build_absolute_uri }}" />
Expand All @@ -16,9 +18,6 @@
<meta name="author" content="{{ author }}" />
<meta name="robots" content="index, follow">
{% endblock %}

{% load staticfiles %}
{% load blog_tags %}
<!-- Latest compiled and minified CSS -->
<link href='https://fonts.googleapis.com/css?family=Poppins:400,300,500,600,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="{% static 'css/style.css' %}" type="text/css">
Expand Down
1 change: 0 additions & 1 deletion django_blog_it/django_blog_it/templates/posts/contact.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{% extends 'posts/new_base.html' %}
{% load blog_tags %}
{% block title %} Contact Us {% endblock %}
{% block blog_content %}
<!-- blog_detail_container starts here -->
<div class="blog_detail_container">
Expand Down
34 changes: 33 additions & 1 deletion django_blog_it/posts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
from django.db.models import Count
from django_blog_it import settings
from django.contrib import messages
from django.http import Http404, JsonResponse
from django.http import JsonResponse
from django.core.mail import EmailMultiAlternatives
from django.template import Context
from django.views.generic import ListView, DetailView
from django.shortcuts import render_to_response
from microurl import google_mini
from django_blog_it.django_blog_it.models import ContactUsSettings


def categories_tags_lists():
Expand Down Expand Up @@ -173,6 +177,34 @@ def contact_us(request):
if not json.loads(r.text)['success']:
return JsonResponse({'error': True, 'response': {"captcha": "Invalid captcha"}})
# email sending
contact_us = ContactUsSettings.objects.last()
# email to admin
subject = 'Blog Suggestions - ' + form.cleaned_data.get("contact_name")
from_email = form.cleaned_data.get("contact_email")
context = Context({
"NAME_OF_USER": form.cleaned_data.get("contact_name"),
"WEBSITE_OF_USER": form.cleaned_data.get("contact_website"),
"USER_DESCRIPTION": form.cleaned_data.get("content"),
"BLOG_TITLE": settings.BLOG_TITLE
})
html_content = render_to_response('emails/email_to_admin.html', context).content.decode("utf-8")
msg = EmailMultiAlternatives(subject, subject, from_email, [contact_us.email_admin])
# msg.attach(html_content, 'text/html')
msg.attach_alternative(html_content, "text/html")
msg.send()
# email to user
subject = 'Thank you for contacting us - ' + settings.BLOG_TITLE
from_email = contact_us.from_email
context = Context({
"BODY_USER": contact_us.body_user,
"BLOG_TITLE": settings.BLOG_TITLE
})
html_content = render_to_response('emails/email_to_user.html', context).content.decode("utf-8")
headers = {'Reply-To': contact_us.reply_to_email}
msg = EmailMultiAlternatives(subject, subject, from_email, [form.cleaned_data.get("contact_email")], headers=headers)
msg.attach_alternative(html_content, "text/html")
msg.send()
# end
messages.success(
request, 'Successfully Sent your contact us details.')
data = {'error': False,
Expand Down

0 comments on commit 2315fe4

Please sign in to comment.