django send_email not sending to host domain email addresses - django

My Django (hosted through a cPanel Python App) is not sending out emails to addresses belonging to the same domain as the site.
The same send_email() function works fine in sending out messages to any other domain.
I use Google Workspace for managing emails, and all MX records are set up via cPanel as normal – and emails otherwise work fine via Gmail.
Any ideas?

Related

Using sendgrid domain authentication sends email to spam in Django

I am trying to send email from my Django application. For this, I have used Twilio SendGrid service. Though my application can send the email, it ends up in spam folder. So, I have followed this tutorial to authenticate my domain which I bought from AWS route 53. In sendgrid, the domain authentication status shows 'verified' but the emails are still sent to spam folder. I have not created any MX or TXT record in DNS setting as the tutorial says it was created automatically during domain authentication in sendgrid.
One thing I have noticed that the email still shows, 'via.sendgrid.net' message (attached an image below) with the email. Whereas it should be my authenticated domain name. I have created sendgrid account with an outlook email and using that address to send email from Django app. Is this the reason my emails are going to spam? Or can anyone please help me to find a solution for this problem? Thanks in advance.
FYI: I have done 'Single Sender Verification' in sendgrid during developing this app. But now I have deployed it in aws. I guess this feature is still working instead of 'Domain Authentication'.

Multiple MX Records

We have a site on Google Cloud, let's call it 'main.co.uk'
and a subdomain site called 'forum'.
We are using Gmail business for main.co.uk emails, verified by MX records, SPF etc
Now what's confusing me is using mailgun for sending mail for 'forum'.
I know we can have multiple MX Records for main.co.uk but is there a good way to do this? do we set different priorities? Will we get issues with mailgun and Google trying to handle incoming mail?
Any advice would be great.
Using mailgun for sending emails does not involve MX records. Services like mailgun will use credentials for one of your email servers and will act like an email client program. Mailgun will authenticate and then upload email to the email server. There is also the option for programs like mailgun to act as an SMTP server for your domain (you can have more than one sending server).
Mailgun can also be configured as an email server for receiving email. However, you do not replace your existing email server, instead you create a subdomain that is then managed by mailgun. In this use case all incoming emails for that subdomain someone#mailgun.example.com are then processed by mailgun. This is similar to having multiple email accounts that you need to login into to read your email. The intent here is for mailgun to apply intelligence to the sending and processing of your email campaigns by managing email bounces, click throughs, etc.
MX records specify the mail server responsible for accepting email. You can have multiple MX records with different priorities but they are pointing to the same email system (collection of servers storing your inbox), not to different servers at different providers. For example, you would not have one MX record point to Gmail and another MX record pointing to Office 365 (or mailgun and Google). Multiple MX records support fault tolerance and failover, not multiple providers.
You can have an email server setup for main.co.uk and another email server setup for forum.main.co.uk but these are separate email server setups (I am ignoring email aliasing). You can have mailgun send email for someone#forum.main.co.uk with a return address anotherperson#main.co.uk. Normally you want to keep the sender address and return address the same so that SPAM filters don't kick in.
In summary, use mailgun to send emails from your website and / or email marketing campaigns and a normal email system (Office 365, Gmail, etc.) for everything else but have them setup as separate independent email systems.

How to configure Django such that emails are sent by both smtp, and to a log file?

I'm frequently plagued by the complaints that email from a django application running on its own Ubuntu LTS 16.04 server, is not being received. Typically these are the password change request emails, so they're part of the standard Django Auth module as I understand it.
Django's sendtestemail appears to work reliably, and many of the expected emails are actually sent and received (from what we can discern). The smtp setup is such that EMAIL_HOST is set to an smtp server on the same network that supports anonymous message relay (from servers on the same network only), and the EMAIL_BACKEND is the typical django.core.mail.backends.smtp.EmailBackend. Using the console backend for testing shows that emails are triggered as we would expect on these various events.
So, what I want to be able to do, is to have both email sent out via the smtp relay as expected, but also be added to a log file, and for this to happen for all emails generated by all the email events in the Django app.
Is this possible using django configuration?
If not, can you recommend a method by which I can both send and log the emails?
Bonus query - can the solution allows me to resend an email using the original content?

How to test routes

I have a webpage that reads webhooks received from mail events and routes
In mailgun I created a subdomain that we actually only use for testing, I can not add MX records to the domain we use.
so for example for my domain "mycompany.com" I have added "testing.mycompany.com"
Now I want to send a mail to "testaccount#testing.mycompany.com" that get forwarded with mailgun routes to my webpage but.
Without being able to add MX records to our main domain, is it possible to configure a solution in mailgun so I can send an email to an unexisting mail "testaccount#testing.mycompany.com" in a newly created subdomain ?

Custom Email Marketing from Django on Slicehost Server

I have a Slicehost slice running django through nginx and apache. This is for a project in which email marketing is a key component. We will need to be able to send up to 10,000 emails in a day from this Django app. We need to recieve email as well, however, that can simply be a forwarder.
What would be your recommended solution? would you setup a postfix mail server on the slice or try to use some 3rd party mail service with an API like MailChimp or constant contact?
Sending thousands of emails from your own machine in a reliable way is very hard.
I would recommend you to use SendGrid. You can use them as a smtp server, so there's no need to code against APIs. They can also receive email and POST the data to a URL on your server.