I am trying to send an email using celery queue @shared_task as below:
# removed imports for clarity
# For debugging
@shared_task(bind=True, name="send_email", max_retries=3, default_retry_delay=10)
def send_email(self, subject, message, from_email, to_email, **kwargs):
"""Send an email"""
try:
send_mail(subject, message, from_email, [to_email], **kwargs)
except Exception as e:
logger.error(e) # configured logger
class Command(BaseCommand):
help = "Send test email"
def handle(self, *args, **options):
try:
send_email.delay(
"Test email",
"This is a test email",
settings.EMAIL_HOST_USER,
"validemail@examle.com",
fail_silently=False,
)
self.stdout.write(self.style.SUCCESS("Email queued successfully"))
except Exception as e:
raise CommandError(e)
And I get
...celery stack trace
raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {'validemail@example.com': (550, b'Please turn on SMTP Authentication in your mail client. 333.kpservers.com\n(altar56.supremepanel56.com) [cpanel_server_ip]:43036 is not permitted to\nrelay through this server without authentication.')}
However when I use direct send_mail
without shared_task it is successful (so it doesn't seem to be a server error)
How do I resolve this error?
I am using redis database
redis://default:*******@********.cloud.redislabs.com:13122