-
Notifications
You must be signed in to change notification settings - Fork 1
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 #2 from fabricadesoftware-ifc/Envio-de-emails-#6
Envio de emails #6
- Loading branch information
Showing
18 changed files
with
71 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"python.analysis.extraPaths": [ | ||
"./__pypackages__/3.11/lib" | ||
] | ||
} |
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 EnvioemailsConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "EnvioEmails" |
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,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 .views import EmailAPIView | ||
|
||
urlpatterns = [ | ||
path('email/', EmailAPIView.as_view(), name='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,31 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. | ||
from rest_framework.views import APIView | ||
from rest_framework import status | ||
from django.core.mail import BadHeaderError, send_mail | ||
from django.core.exceptions import ValidationError | ||
from django.http import HttpResponse | ||
|
||
|
||
class EmailAPIView(APIView): | ||
def post(self, request, *args, **kwargs): | ||
subject = request.POST.get("subject", "teste") | ||
print(subject) | ||
message = request.POST.get("message", "testando") | ||
recipient_list = ["[email protected]", "[email protected]"] | ||
|
||
try: | ||
send_mail( | ||
subject, | ||
message, | ||
recipient_list=recipient_list, | ||
from_email="[email protected]", | ||
) | ||
except BadHeaderError: | ||
return HttpResponse("Invalid header found.") | ||
except ValidationError as e: | ||
return HttpResponse(str(e)) | ||
return HttpResponse( | ||
{"message": "Email enviado com sucesso"}, status=status.HTTP_200_OK | ||
) |
Empty file.
Empty file.
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 |
---|---|---|
@@ -1,19 +0,0 @@ | ||
from django.shortcuts import render | ||
|
||
from rest_framework import status | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
from django.core.mail import send_mail | ||
from django.conf import settings | ||
|
||
class SendEmailView(APIView): | ||
def post(self, request): | ||
subject = request.data.get('subject') | ||
message = request.data.get('message') | ||
from_email = settings.EMAIL_HOST_USER | ||
recipient_list = [request.data.get('recipient_email')] | ||
|
||
send_mail(subject, message, from_email, recipient_list, fail_silently=False) | ||
|
||
return Response({"message": "E-mail enviado com sucesso!"}, status=status.HTTP_200_OK) | ||
|
||
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 |
---|---|---|
@@ -1,22 +1,11 @@ | ||
from django.contrib import admin | ||
from django.urls import include,path | ||
from usuario.router import router as usuario_router | ||
from FabricaClass.views import SendEmailView | ||
import requests | ||
|
||
|
||
|
||
urlpatterns = [ | ||
path("admin/", admin.site.urls), | ||
path("api/", include(usuario_router.urls)), | ||
path('send-email/', SendEmailView.as_view(), name='send-email'), | ||
path('emails/', include('EnvioEmails.urls')), | ||
] | ||
|
||
|
||
data = { | ||
'subject': 'Assunto e-mail', | ||
'message': 'Corpo do e-mail', | ||
'recipient_email': '[email protected]' | ||
|
||
} | ||
|
||
response = requests.post('http://link-aplicação/send-email/', data=data) | ||
print(response.status_code, response.content) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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