'Email Not Sending in AWS SES

Settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True  
EMAIL_HOST = 'email-smtp.us-west-2.amazonaws.com'  
EMAIL_HOST_USER =  config('SMTP_USER')
EMAIL_HOST_PASSWORD =  config('SMTP_PW')
EMAIL_PORT = 587

VERIFIED_IDENTITY = config('VERIFIED_IDENTITY')

I have a verified email in my AWS SES and I am trying to send a message. I get a sent message everytime I use my contact form but no message actually gets sent.

        if 'contactForm' in request.POST:
            #print('Contact form')
            contact_form = ContactForm(request.POST)
            if contact_form.is_valid():
                contact_form.save()
                email_subject = f'New contact {contact_form.cleaned_data["email"]}: {contact_form.cleaned_data["subject"]}'
                email_message = contact_form.cleaned_data['message']
                print(email_subject,email_message)
                try:
                    send_mail(email_subject, email_message,settings.VERIFIED_IDENTITY,[settings.VERIFIED_IDENTITY])
                except BadHeaderError: 
                    print('bad')

enter image description here



Solution 1:[1]

In my opinion the issue might be related to DNS SPF record. See below the link related.

"A sender policy framework (SPF) record is a type of DNS TXT record that lists all the servers authorized to send emails from a particular domain." https://www.cloudflare.com/learning/dns/dns-records/dns-spf-record/#:~:text=A%20sender%20policy%20framework%20(SPF,Domain%20Name%20System%20(DNS).

https://docs.aws.amazon.com/ses/latest/dg/send-email-authentication-spf.html

To set up SPF, you publish a TXT record to the DNS configuration for your domain. This record contains a list of the servers that you authorize to send email from your domain. When an email provider receives a message from your domain, it checks the DNS records for your domain to make sure that the email was sent from an authorized server.

Regards, Ed.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eduardo Estevez Nunez