Reputation: 1
When I try to send and email from django running on AWSAppRunner instance, the screen stays loading for a while and then it turns all white. If I open my debugger, I see a 502 network error: Origin checking failed {My DOMAIN APPEARED HERE } does not match any trusted origins.
I Forbidden (403) CSRF verification failed. Request aborted. Reason given for failure: Origin checking failed does not match any trusted origins and I added these credentials mentioned in that stack page (CSRF_TRUSTED_ORIGINS,CORS_ORIGIN_WHITELIST, CORS_ALLOWED_ORIGINS, SECURE_PROXY_SSL_HEADER) and then got this error. Origin checking failed - null does not match any trusted origins.
I do have the CSFR token on my html {% csrf_token %}. I know its the email because I comment that send_email function and everything works as expected. I verified the identities (from email and to email) in AWS SES. I installed SES with pip and added :
EMAIL_BACKEND = 'django_ses.SESBackend' AWS_SES_REGION_NAME = 'us-east-2' AWS_SES_REGION_ENDPOINT = 'email.us-east-2.amazonaws.com'
I also have my access key, I was able to send the email using my localhost (My own computer running python manage.py runserver). I allowed all trafic in and out on the security group.
What else can I try ?
def nuevaorden_view(request):
if request.method == "POST":
try:
nombre = request.POST.get("nombre")
email = request.POST.get("email")
telefono = request.POST.get("telefono")
TipoDeServicio = request.POST.get("TipoDeServicio")
ServiciosCombinados = request.POST.getlist("ServiciosCombinados")
FrecuenciaDeServicio = request.POST.get("FrecuenciaDeServicio")
Description = request.POST.get("Description")
CiudadOrigen = request.POST.get("CiudadOrigen")
PaisOrigen = request.POST.get("PaisOrigen")
CodigoPostalOrigen = request.POST.get("CodigoPostalOrigen")
CiudadDestino = request.POST.get("CiudadDestino")
PaisDestino = request.POST.get("PaisDestino")
CodigoPostalDestino = request.POST.get("CodigoPostalDestino")
Status = 'Orden Abierta'
Carrier = 'CorreKaminos'
orden = NuevaOrden(
nombre=nombre,
email=email,
telefono=telefono,
TipoDeServicio=TipoDeServicio,
ServiciosCombinados=ServiciosCombinados,
FrecuenciaDeServicio=FrecuenciaDeServicio,
Description=Description,
CiudadOrigen=CiudadOrigen,
PaisOrigen=PaisOrigen,
CodigoPostalOrigen=CodigoPostalOrigen,
CiudadDestino=CiudadDestino,
PaisDestino=PaisDestino,
CodigoPostalDestino=CodigoPostalDestino,
Status=Status,
Carrier=Carrier
)
try:
orden.save()
except Exception as e:
print(e)
# Save the instance to the database
try:
mail_subject = "Nueva orden"
message = ('Una nueva orden ha sido creada.')
from_email = "[email protected]"
to_email = ['[email protected]']
send_mail(mail_subject, message, from_email, to_email, fail_silently=False)
messages.success(request, "La orden se ha creado correctamente.")
return render(request, "ordenes/ordenregistrada.html")
except Exception as e:
# Handle other exceptions (e.g., email sending failure)
print(e)
return render(request, "ordenes/nuevaorden.html")
except Exception as e:
print(e)
return render(request, "ordenes/nuevaorden.html")
Upvotes: 0
Views: 69