fixed email error
This commit is contained in:
@@ -41,6 +41,8 @@ DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
|
|||||||
|
|
||||||
EMAIL_BACKEND = "anymail.backends.amazon_ses.EmailBackend"
|
EMAIL_BACKEND = "anymail.backends.amazon_ses.EmailBackend"
|
||||||
DEFAULT_FROM_EMAIL = "no-reply@latienda.com"
|
DEFAULT_FROM_EMAIL = "no-reply@latienda.com"
|
||||||
|
# DEFAULT_FROM_EMAIL = "samuel.molina@enreda.coop"
|
||||||
|
|
||||||
SERVER_EMAIL = "mail-server@latienda.com"
|
SERVER_EMAIL = "mail-server@latienda.com"
|
||||||
|
|
||||||
ANYMAIL = {
|
ANYMAIL = {
|
||||||
|
|||||||
@@ -267,13 +267,13 @@ def purchase_email(request):
|
|||||||
return Response({"error": "Required parameters for anonymous user: telephone, company, product, comment"}, status=status.HTTP_406_NOT_ACCEPTABLE)
|
return Response({"error": "Required parameters for anonymous user: telephone, company, product, comment"}, status=status.HTTP_406_NOT_ACCEPTABLE)
|
||||||
|
|
||||||
if request.user.is_anonymous:
|
if request.user.is_anonymous:
|
||||||
email = data.get('email')
|
user_email = data.get('email')
|
||||||
else:
|
else:
|
||||||
email = request.user.email
|
user_email = request.user.email
|
||||||
telephone = data.get('telephone')
|
telephone = data.get('telephone')
|
||||||
# validate email
|
# validate email
|
||||||
try:
|
try:
|
||||||
validate_email(email)
|
validate_email(user_email)
|
||||||
except:
|
except:
|
||||||
return Response({"error": "Value for email is not valid"}, status=status.HTTP_406_NOT_ACCEPTABLE)
|
return Response({"error": "Value for email is not valid"}, status=status.HTTP_406_NOT_ACCEPTABLE)
|
||||||
# get company
|
# get company
|
||||||
@@ -287,7 +287,7 @@ def purchase_email(request):
|
|||||||
# check company.email
|
# check company.email
|
||||||
if company.email is None:
|
if company.email is None:
|
||||||
return Response({"error": "Related compay has no contact email address"}, status=status.HTTP_406_NOT_ACCEPTABLE)
|
return Response({"error": "Related compay has no contact email address"}, status=status.HTTP_406_NOT_ACCEPTABLE)
|
||||||
|
try:
|
||||||
# send email to company
|
# send email to company
|
||||||
company_message = render_to_string('purchase_notification.html', {
|
company_message = render_to_string('purchase_notification.html', {
|
||||||
'company': company,
|
'company': company,
|
||||||
@@ -306,9 +306,11 @@ def purchase_email(request):
|
|||||||
'company_message': company_message,
|
'company_message': company_message,
|
||||||
})
|
})
|
||||||
subject = 'Confirmación de petición de compra'
|
subject = 'Confirmación de petición de compra'
|
||||||
email = EmailMessage(subject, user_message, to=[email])
|
email = EmailMessage(subject, user_message, to=[user_email])
|
||||||
email.send()
|
email.send()
|
||||||
logging.info(f"Purchase Contact confirmation email sent to {email}")
|
logging.info(f"Purchase Contact confirmation email sent to {user_email}")
|
||||||
|
except Exception as e:
|
||||||
|
return Response({'error': f"Could not send emails [{str(type(e))}]: {str(e)}"}, status=500)
|
||||||
|
|
||||||
# create statslog instance to register interaction
|
# create statslog instance to register interaction
|
||||||
stats_data = {
|
stats_data = {
|
||||||
|
|||||||
Reference in New Issue
Block a user