forked from Kamva-Academy/Kamva-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from sepid-org/email-service
Email Service
- Loading branch information
Showing
26 changed files
with
601 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from manage_content_service.celery_app import app as celery_app | ||
|
||
__all__ = ("celery_app",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import os | ||
from celery import Celery | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'manage_content_service.settings.development') | ||
app = Celery() | ||
app.config_from_object('django.conf:settings', namespace="CELERY") | ||
app.autodiscover_tasks() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ def get_environment_var(var_name, default, prefixed=True): | |
return os.getenv(var_name, default) | ||
|
||
|
||
CORS_ORIGIN_ALLOW_ALL = True | ||
|
||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | ||
BASE_DIR = os.path.dirname(os.path.dirname( | ||
os.path.dirname(os.path.abspath(__file__)))) | ||
|
@@ -43,6 +45,8 @@ def get_environment_var(var_name, default, prefixed=True): | |
'rest_framework.authtoken', | ||
'import_export', | ||
'drf_yasg', | ||
'celery', | ||
'messenger', | ||
'polymorphic', | ||
'django_extensions', | ||
'django_filters', | ||
|
@@ -72,26 +76,6 @@ def get_environment_var(var_name, default, prefixed=True): | |
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
] | ||
# multi-lingual settings below | ||
# LANGUAGES = [ | ||
# ('en', _('English')), | ||
# ('fa', _('Persian')), | ||
# ] | ||
|
||
# USE_I18N = True | ||
# | ||
# USE_L10N = True | ||
# | ||
# LANGUAGE_CODE = 'en' | ||
# | ||
# LOCALE_PATHS = [ | ||
# os.path.join(BASE_DIR, 'locale'), | ||
# ] | ||
# multilingual settings above | ||
|
||
CORS_ORIGIN_ALLOW_ALL = True | ||
|
||
ROOT_URLCONF = 'manage_content_service.urls' | ||
|
||
TEMPLATES = [ | ||
{ | ||
|
@@ -109,6 +93,7 @@ def get_environment_var(var_name, default, prefixed=True): | |
}, | ||
] | ||
|
||
|
||
WSGI_APPLICATION = 'manage_content_service.wsgi.application' | ||
|
||
# Password validation | ||
|
@@ -151,31 +136,17 @@ def get_environment_var(var_name, default, prefixed=True): | |
MEDIA_URL = '/api/media/' | ||
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') | ||
|
||
EMAIL_HOST = 'smtp.zoho.com' | ||
EMAIL_HOST_USER = '[email protected]' | ||
EMAIL_HOST_PASSWORD = 'ET6vmrh.$gHZFjL' | ||
EMAIL_PORT = 587 | ||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' | ||
EMAIL_HOST = 'smtp.gmail.com' | ||
EMAIL_USE_TLS = True | ||
EMAIL_USE_SSL = False | ||
DEFAULT_FROM_EMAIL = "Rastaiha <" + EMAIL_HOST_USER + ">" | ||
|
||
# Activate Django-Heroku. | ||
|
||
OK_STATUS = 'ok' | ||
ERROR_STATUS = 'err' | ||
HELP_STATUS = 'help' | ||
|
||
THUMBNAIL_ALIASES = { | ||
'': { | ||
'avatar': {'size': (80, 80), 'crop': True}, | ||
}, | ||
} | ||
EMAIL_PORT = 587 | ||
EMAIL_HOST_USER = '[email protected]' | ||
EMAIL_HOST_PASSWORD = 'tmyz glmk cjsj urnw' | ||
|
||
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage' | ||
|
||
CONSTANTS = { | ||
"PAGINATION_NUMBER": 50, | ||
|
||
} | ||
|
||
# Custom user model | ||
|
@@ -227,6 +198,17 @@ def get_environment_var(var_name, default, prefixed=True): | |
PURCHASE_UNIQ_CODE_LENGTH = 10 | ||
|
||
|
||
########## Celery ########## | ||
|
||
CELERY_TIMEZONE = TIME_ZONE | ||
CELERY_TASK_TRACK_STARTED = True | ||
CELERY_TASK_TIME_LIMIT = 30 * 60 | ||
ROOT_URLCONF = 'manage_content_service.urls' | ||
CELERY_BROKER_URL = get_environment_var('BROKER_URL', 'amqp://') | ||
|
||
|
||
########## Zarrinpal Payment ########## | ||
|
||
def GET_PAYMENT_CALLBACK_URL(domain, status): | ||
PAYMENT = { | ||
'success': f'http://{domain}/message/payment/success', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,8 @@ | |
|
||
ALLOWED_HOSTS = ['*'] | ||
|
||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class MessengerConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'messenger' |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from celery import shared_task | ||
from django.core.mail import EmailMessage | ||
|
||
|
||
@shared_task() | ||
def send_email_task(subject, recipients_emails, body): | ||
sender_email = '[email protected]' | ||
mail = EmailMessage(subject=subject, body=body, | ||
from_email=sender_email, to=recipients_emails) | ||
mail.content_subtype = 'html' | ||
try: | ||
mail.send() | ||
return True | ||
except: | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.urls import path | ||
from messenger.views import * | ||
|
||
urlpatterns = [ | ||
path('test/', send_email) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import os | ||
from django.http import HttpResponse | ||
from messenger.tasks import send_email_task | ||
from manage_content_service.settings.base import BASE_DIR | ||
|
||
|
||
import requests | ||
from django.http import JsonResponse | ||
from django.views.decorators.csrf import csrf_exempt | ||
from django.shortcuts import redirect | ||
|
||
@csrf_exempt | ||
def send_email(request): | ||
if request.method == 'POST': | ||
email_data = { | ||
# todo: convert it to recipients: | ||
"email": request.POST.get("email"), | ||
"subject": request.POST.get("subject"), | ||
"body": request.POST.get("body") | ||
# todo: add a field for choosing template | ||
} | ||
response = requests.post("http://127.0.0.1:8080/send-email/", json=email_data) | ||
|
||
if response.status_code == 200: | ||
return JsonResponse({"message": "Email has been sent"}, status=200) | ||
else: | ||
return JsonResponse({"error": "Failed to send email"}, status=500) | ||
|
||
return JsonResponse({"error": "Invalid request method"}, status=405) | ||
|
||
|
||
|
||
# def send_email(request): | ||
# html_content =os.path.join(BASE_DIR, "assets/greeting_mail.html") | ||
# html_content= open(html_content, "r", encoding="utf-8").read() | ||
# send_emailQeue.delay("ehsna" , "[email protected]" , html_content) | ||
# return HttpResponse("goi") | ||
|
||
|
||
# def send_email(request): | ||
# subject = 'Subject of the email' | ||
# message = 'This is the message body.' | ||
# from_email = '[email protected]' # Sender's email address | ||
# | ||
# # List of recipient email addresses | ||
# recipient_list = ['[email protected]'] | ||
# | ||
# send_mail(subject, message, from_email, recipient_list) | ||
# return HttpResponse('Email sent successfully!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# email api: https://smtp.sepid.org/send-email/ | ||
|
||
# todo: remove messenger app | ||
|
||
def send_email(): | ||
# todo | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
SMS_CODE_DELAY = 5 | ||
SMS_CODE_LENGTH = 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from proxies.sms_system.sms_service_interface import SMSService | ||
|
||
|
||
class SMSServiceFacade(SMSService): | ||
provider: SMSService = None | ||
|
||
def __init__(self, provider: str) -> None: | ||
if provider == 'kavenegar': | ||
from proxies.sms_system.kavenegar import KaveNegarSMSService | ||
from django.conf import settings | ||
self.provider = KaveNegarSMSService(token=settings.KAVENEGAR_TOKEN) | ||
|
||
def send_otp(self, receptor_phone_number, action, token, token2=None, token3=None): | ||
self.provider.send_otp(receptor_phone_number, | ||
action, token, token2, token3) | ||
|
||
def send_sms(self): | ||
self.provider.send_sms() | ||
|
||
def send_bulk(self): | ||
self.provider.send_bulk() |
Oops, something went wrong.