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).
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.
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.
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.
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.