fixed email error
This commit is contained in:
@@ -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)
|
||||
|
||||
if request.user.is_anonymous:
|
||||
email = data.get('email')
|
||||
user_email = data.get('email')
|
||||
else:
|
||||
email = request.user.email
|
||||
user_email = request.user.email
|
||||
telephone = data.get('telephone')
|
||||
# validate email
|
||||
try:
|
||||
validate_email(email)
|
||||
validate_email(user_email)
|
||||
except:
|
||||
return Response({"error": "Value for email is not valid"}, status=status.HTTP_406_NOT_ACCEPTABLE)
|
||||
# get company
|
||||
@@ -287,28 +287,30 @@ def purchase_email(request):
|
||||
# check company.email
|
||||
if company.email is None:
|
||||
return Response({"error": "Related compay has no contact email address"}, status=status.HTTP_406_NOT_ACCEPTABLE)
|
||||
|
||||
# send email to company
|
||||
company_message = render_to_string('purchase_notification.html', {
|
||||
'company': company,
|
||||
'user': request.user,
|
||||
'product': product,
|
||||
'telephone': data['telephone'],
|
||||
})
|
||||
subject = "[latienda.coop] Solicitud de compra"
|
||||
email = EmailMessage(subject, company_message, to=[company.email])
|
||||
email.send()
|
||||
logging.info(f"Email sent to {company}")
|
||||
# send confirmation email to user
|
||||
user_message = render_to_string('purchase_contact_confirmation.html', {
|
||||
'company': company,
|
||||
'product': product,
|
||||
'company_message': company_message,
|
||||
})
|
||||
subject = 'Confirmación de petición de compra'
|
||||
email = EmailMessage(subject, user_message, to=[email])
|
||||
email.send()
|
||||
logging.info(f"Purchase Contact confirmation email sent to {email}")
|
||||
try:
|
||||
# send email to company
|
||||
company_message = render_to_string('purchase_notification.html', {
|
||||
'company': company,
|
||||
'user': request.user,
|
||||
'product': product,
|
||||
'telephone': data['telephone'],
|
||||
})
|
||||
subject = "[latienda.coop] Solicitud de compra"
|
||||
email = EmailMessage(subject, company_message, to=[company.email])
|
||||
email.send()
|
||||
logging.info(f"Email sent to {company}")
|
||||
# send confirmation email to user
|
||||
user_message = render_to_string('purchase_contact_confirmation.html', {
|
||||
'company': company,
|
||||
'product': product,
|
||||
'company_message': company_message,
|
||||
})
|
||||
subject = 'Confirmación de petición de compra'
|
||||
email = EmailMessage(subject, user_message, to=[user_email])
|
||||
email.send()
|
||||
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
|
||||
stats_data = {
|
||||
|
||||
Reference in New Issue
Block a user