Cpanel Django SMTP Problem: Mails Dont Show Up
Im sending mails in my Django project though my mail hosting with SSL settings.
Eventhough I cant detect any problems with the SMTP code and mails are seem to sent in the cpanels tracking page, the mails dont show up in the inbox.
I tried it for gmail and outlook it didnt work.
Settings:
EMAIL_HOST = '<server_name>'
EMAIL_PORT = 465
EMAIL_HOST_USER = 'info@my_mail.com'
EMAIL_HOST_PASSWORD = '********'
View
class SendMailTest(APIView):
def post(self, request):
recipient_email = 'recipient@mail.com'
msg = MIMEMultipart()
msg['From'] = settings.EMAIL_HOST_USER
msg['To'] = recipient_email
msg['Subject'] = 'SMTP Test Mail'
html_content = "<h1>This is a test email</h1><p>Sent via Django.</p>"
msg.attach(MIMEText(html_content, 'html'))
context = ssl.create_default_context()
with smtplib.SMTP_SSL(settings.EMAIL_HOST, settings.EMAIL_PORT, context=context) as server:
server.set_debuglevel(1)
server.login(settings.EMAIL_HOST_USER, settings.EMAIL_HOST_PASSWORD)
server.sendmail(settings.EMAIL_HOST_USER, recipient_email, msg.as_string())
return Response({'status': 'success'})
Debug Log Summary:
reply: b'235 Authentication succeeded\r\n'
reply: retcode (235); Msg: b'Authentication succeeded'
send: 'mail FROM:<info@my_mail.com> size=412\r\n'
reply: b'250 OK\r\n'
reply: retcode (250); Msg: b'OK'
send: 'rcpt TO:<'recipient@mail.com'>\r\n'
reply: b'250 Accepted\r\n'
reply: retcode (250); Msg: b'Accepted'
send: 'data\r\n'
reply: b'354 Enter message, ending with "." on a line by itself\r\n'
reply: retcode (354); Msg: b'Enter message, ending with "." on a line by itself'
data: (354, b'Enter message, ending with "." on a line by itself')
send: b'Content-Type: multipart/mixed;....
reply: b'250 OK id=1tYlca-0000000DgLn-0Cg7\r\n'
reply: retcode (250); Msg: b'OK id=1tYlca-0000000DgLn-0Cg7'
data: (250, b'OK id=1tYlca-0000000DgLn-0Cg7')
send: 'QUIT\r\n'
reply: b'221 <server_name> closing connection\r\n'
reply: retcode (221); Msg: b'cp64.servername.co closing connection'