From fda0fcf35c1c9155921bfd7c698e559b1a8a17af Mon Sep 17 00:00:00 2001 From: harsha Date: Fri, 31 Dec 2021 14:31:41 +0530 Subject: [PATCH] Query box mails admin gitignore added and messages in query box are sent to admin users mail --- .gitignore | 137 ++++++++++++++++++++++++++++++++++++++++++++++ AIWeb/features.py | 31 +++++++++++ AIWeb/views.py | 13 +++-- 3 files changed, 177 insertions(+), 4 deletions(-) create mode 100644 .gitignore create mode 100644 AIWeb/features.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fe7b0fd --- /dev/null +++ b/.gitignore @@ -0,0 +1,137 @@ +# Django # +*.log +*.pot +*.pyc +__pycache__ +db.sqlite3 +media + +# Backup files # +*.bak + +# If you are using PyCharm # +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# File-based project format +*.iws + +# IntelliJ +out/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Python # +*.py[cod] +*$py.class + +# Distribution / packaging +.Python build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +.pytest_cache/ +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery +celerybeat-schedule.* + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# Sublime Text # +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache +*.sublime-workspace +*.sublime-project + +# sftp configuration file +sftp-config.json + +# Package control specific files Package +Control.last-run +Control.ca-list +Control.ca-bundle +Control.system-ca-bundle +GitHub.sublime-settings + +# Visual Studio Code # +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +.history \ No newline at end of file diff --git a/AIWeb/features.py b/AIWeb/features.py new file mode 100644 index 0000000..812979a --- /dev/null +++ b/AIWeb/features.py @@ -0,0 +1,31 @@ +import smtplib, ssl +from email.mime.text import MIMEText +from email.mime.multipart import MIMEMultipart +import threading + + +def send_mail_toadmins(mail_from, concern, phone, email_id, admin_mails, subject="You got a message from AILobby", + sender_email="ailobby2021@gmail.com", + password="ArtificialIntelligence@2021"): + message = MIMEMultipart("alternative") + message["Subject"] = subject + message["From"] = sender_email + text = f"""\ + Message from {mail_from} + His concern is : + {concern} + You can call him on {phone} + You can mail him at {email_id} + """ + + part1 = MIMEText(text, "plain") + + message.attach(part1) + + context = ssl.create_default_context() + with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server: + server.login(sender_email, password) + for receiver_email in admin_mails: + server.sendmail( + sender_email, receiver_email, message.as_string() + ) \ No newline at end of file diff --git a/AIWeb/views.py b/AIWeb/views.py index aa90dba..2f30ee4 100644 --- a/AIWeb/views.py +++ b/AIWeb/views.py @@ -1,6 +1,8 @@ from django.shortcuts import render, HttpResponse -from .models import Contact,contactForm,Project,DigitalNote - +from .models import Contact, contactForm, Project, DigitalNote +from django.contrib.auth.models import User +from .features import * +import threading # Create your views here. def index(request): @@ -18,6 +20,9 @@ def contact(request): print(name, email, phone, concern) contactObj = Contact(name=name, email=email, phone=phone, desc=concern) contactObj.save() + adminEmails = [user.email for user in User.objects.all()] + mailingThread = threading.Thread(target=send_mail_toadmins,args=(name,concern,phone,email,adminEmails)) + mailingThread.start() form = contactForm() return render(request, 'AIWeb/contact.html', {'form': form, 'submitted': True, 'try': True}) else: @@ -37,5 +42,5 @@ def events(request): def academics(request): - digitalNotes = {'allSubject':list(DigitalNote.objects.all())[::-1]} - return render(request, 'AIWeb/academics.html',digitalNotes) + digitalNotes = {'allSubject': list(DigitalNote.objects.all())} + return render(request, 'AIWeb/academics.html', digitalNotes)