eMail error when deploying

This is probably minor, but one of my servers seems to have an issue sending mail when a deploy starts. The error pops up after asking for the vault password on a deploy as well as at the end of the deploy:

Ubuntu 22.04.4 LTS
Traceback (most recent call last):
  File "/home/cchq/www/monolith/releases/2024-05-11_18.43/manage.py", line 190, in <module>
    main()
  File "/home/cchq/www/monolith/releases/2024-05-11_18.43/manage.py", line 48, in main
    execute_from_command_line(sys.argv)
  File "/home/cchq/www/monolith/releases/2024-05-11_18.43/python_env/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/cchq/www/monolith/releases/2024-05-11_18.43/python_env/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/cchq/www/monolith/releases/2024-05-11_18.43/python_env/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/cchq/www/monolith/releases/2024-05-11_18.43/python_env/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/home/cchq/www/monolith/releases/2024-05-11_18.43/corehq/apps/hqadmin/management/commands/send_email.py", line 45, in handle
    mail_admins(subject, message, html_message=message if is_html else None)
  File "/home/cchq/www/monolith/releases/2024-05-11_18.43/python_env/lib/python3.9/site-packages/django/core/mail/__init__.py", line 104, in mail_admins
    mail.send(fail_silently=fail_silently)
  File "/home/cchq/www/monolith/releases/2024-05-11_18.43/python_env/lib/python3.9/site-packages/django/core/mail/message.py", line 284, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/cchq/www/monolith/releases/2024-05-11_18.43/python_env/lib/python3.9/site-packages/django/core/mail/backends/smtp.py", line 109, in send_messages
    sent = self._send(message)
  File "/home/cchq/www/monolith/releases/2024-05-11_18.43/python_env/lib/python3.9/site-packages/django/core/mail/backends/smtp.py", line 125, in _send
    self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='\r\n'))
  File "/usr/lib/python3.9/smtplib.py", line 908, in sendmail
    raise SMTPDataError(code, resp)
smtplib.SMTPDataError: (501, b'5.6.0 Request body validation error. Need either non-empty Html or PlainText body to be present.')
Connection to 10.3.0.4 closed.

It's worth noting that we've recently switched to Azure Communication Services to send mail (SMTP).

Also to mention, the "deploy successful" email goes off without error and Commcare is able to send general user mails without issues (user creation, password reset, etc.) so it seems it's only at the start of the deploy that it's failing to send mail (doesn't affect the deploy).

Thank you for reporting this Ed.

When you see this next, if you can share the specific command that is being run by commcare cloud that leads to this error, that would be helpful to point to where this could be originating from.

I believe entering the vault password as a step is leading to an unexpected email request body.

Hi Manish, it happens with a cchq monolith deploy
It then asks for the vault password and shortly after that the mail failure. I'll do a short screen grab at the next opportunity.

Sure Ed, thank you!

Feel free to share if you are able to.

Hi @mkangia, here's the full error I receive:

Are you sure you want to deploy to monolith? [y/N]y
Vault Password for 'monolith':
>> Sending email: ATTENTION: ccc has initiated a CommCare HQ deploy to monolith with non-default branch '008fff7'
Ubuntu 22.04.4 LTS
Traceback (most recent call last):
  File "/home/cchq/www/monolith/releases/2024-05-18_07.08/manage.py", line 190, in <module>
    main()
  File "/home/cchq/www/monolith/releases/2024-05-18_07.08/manage.py", line 48, in main
    execute_from_command_line(sys.argv)
  File "/home/cchq/www/monolith/releases/2024-05-18_07.08/python_env/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/home/cchq/www/monolith/releases/2024-05-18_07.08/python_env/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/cchq/www/monolith/releases/2024-05-18_07.08/python_env/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/cchq/www/monolith/releases/2024-05-18_07.08/python_env/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
    output = self.handle(*args, **options)
  File "/home/cchq/www/monolith/releases/2024-05-18_07.08/corehq/apps/hqadmin/management/commands/send_email.py", line 45, in handle
    mail_admins(subject, message, html_message=message if is_html else None)
  File "/home/cchq/www/monolith/releases/2024-05-18_07.08/python_env/lib/python3.9/site-packages/django/core/mail/__init__.py", line 104, in mail_admins
    mail.send(fail_silently=fail_silently)
  File "/home/cchq/www/monolith/releases/2024-05-18_07.08/python_env/lib/python3.9/site-packages/django/core/mail/message.py", line 284, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/cchq/www/monolith/releases/2024-05-18_07.08/python_env/lib/python3.9/site-packages/django/core/mail/backends/smtp.py", line 109, in send_messages
    sent = self._send(message)
  File "/home/cchq/www/monolith/releases/2024-05-18_07.08/python_env/lib/python3.9/site-packages/django/core/mail/backends/smtp.py", line 125, in _send
    self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='\r\n'))
  File "/usr/lib/python3.9/smtplib.py", line 908, in sendmail
    raise SMTPDataError(code, resp)
smtplib.SMTPDataError: (501, b'5.6.0 Request body validation error. Need either non-empty Html or PlainText body to be present.')
Connection to 10.3.0.4 closed.

Thank you @erobinson.

Just noting here that the error does not block deploy but the email for the deploy is failing, likely due to the step to enter ansible vault resulting in email content being faulty.

1 Like

And just to add, other emails are sent without issue including two 'success' emails after deployment:

It seems the one just before deployment and just before formplayer deployment are the only ones failing at this point.

Hi Ed,

Thank you for posting about this error.

Notifications of the start of a deploy and of a failed deploy both have empty message bodies. AWS's SMTP service is fine with that, but clearly Azure's is not.

I have made a code change to set the message body to the same as the subject line if the message body is empty. You can track that pull request here.

1 Like

Norman, you are a legend. Thank you!

Just to close the loop on this, the pull request is merged. Updating CommCare Cloud should allow it to send emails using Azure Communication Services.

1 Like

Excellent, thanks Norman, greatly appreciated!
EDIT I got to test this over the weekend and problem resolved, thanks guys!