Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that SMTP message body is not empty #6313

Merged
merged 4 commits into from
Jun 19, 2024
Merged

Ensure that SMTP message body is not empty #6313

merged 4 commits into from
Jun 19, 2024

Conversation

kaapstorm
Copy link
Contributor

Context: Forum

Email notifications of both the start of a deploy, and of a failed deploy, have empty message bodies. Azure Communication Services rejects emails with empty message bodies with the following exception:

smtplib.SMTPDataError: (501, b'5.6.0 Request body validation error. Need either non-empty Html or PlainText body to be present.')

Environments Affected

Only affects environments that use Azure Communication Services for SMTP. No Dimagi environments are affected.

Email notifications of both the start of a deploy, and of a failed
deploy, have empty message bodies. Azure Communication Services rejects
emails with empty message bodies with:

> smtplib.SMTPDataError: (501, b'5.6.0 Request body validation error. Need either non-empty Html or PlainText body to be present.')
@kaapstorm kaapstorm requested review from mkangia and gherceg June 7, 2024 10:07
:param subject: Email subject
:param message: Email message
:param to_admins: True if mail should be sent to Django admins
:param recipients: List of additional addresses to send mail to
"""
if environment.fab_settings_config.email_enabled:
print(color_summary(f">> Sending email: {subject}"))

if not message:
# Azure Communication Services require a message body
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, its only for Azure.

I'd say we don't make any change for this.
To cater to a restriction to on email provider, we are populating emails for all providers.
& I don't believe that empty email body is unusual, so its not clear why Azure isn't happy about it.

If we absolutely need to fix this, we could just catch the exception from provider and give a nicer message though the exception itself seems totally okay too since this is not because of any issues with commcare-cloud.

So, I'd say we don't address this error.

Copy link
Contributor Author

@kaapstorm kaapstorm Jun 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, its only for Azure.

According to HG Insights:

In 2024, Azure market share reached 24% of the global cloud computing market and their customer base grew by 14.2% from 2023 to 2024.

...

I don't believe that empty email body is unusual, so its not clear why Azure isn't happy about it.

Microsoft's implementations of Internet standards is an old and interesting discussion, but it seems only academic. I think we have to be pragmatic. What is the best way to deal with the situation we have?

I think there are two facts that persuade me that this change is good:

  1. Azure has a quarter of the cloud market, so it is not unrealistic to expect that some of Dimagi's self-hosting partners will use Azure to host HQ.
  2. An important partner is using Azure to host HQ right now.

I don't understand why you are recommending that we prevent our self-hosting partners from receiving notifications. That sounds like a footgun to me.

Alternatively, if you feel that this specific implementation of a solution is incorrect, would you be amenable to changing the notifications for start and failure to have message bodies, since the notification for success has a message body already?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @kaapstorm

Solid facts about the Azure usage, I was not aware its that widely used.

I don't understand why you are recommending that we prevent our self-hosting partners from receiving notifications. That sounds like a footgun to me.

Definitely not saying we should not notify. I see that commcare cloud is attempting to send the notification, but its failing due to restrictions at the email provider. I am aligned that we should make reasonable changes to cater for requirements of different integrations we have. My hesitation was to modify implementations for all email providers to cater for one email provider.

would you be amenable to changing the notifications for start and failure to have message bodies

I see that would resolve the concern currently for these emails. In future, if another email is added without a message body, the same error is going to appear. And I see that the change you are making takes care of that.

If here we acknowledge that some email providers block emails that don't have a body & in commcare cloud we want to take care of that generally & to cater for that we would use the subject as the email body if its missing, I am okay with that.

An alternate could be to

  1. add email body for the emails that don't have one
  2. raise an error if message body is missing so that the dev can add one

Moreover, happy to go with whatever the team decides.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea. 358dcce and 19547c9

Set the subject to the message because the message is short.
@kaapstorm
Copy link
Contributor Author

I'm curious what others think, @dannyroberts @gherceg ? How do you feel about setting a message body if it is empty? Alternatively, should we pass a message body to send_email() in the two places where it is called without one? Or is it best not to send notifications when HQ is hosted on Azure?

@kaapstorm
Copy link
Contributor Author

Bump. @snopoke and @AmitPhulera I noticed you've worked in this module. Any thoughts or opinions on this change?

@AmitPhulera
Copy link
Contributor

@kaapstorm The change looks reasonable to me. I also looked briefly into it while going through the forum and I had a similar approach in mind for the fix.
One question, do we know how it changes the deploy emails? Like how they used to appear before and how they would appear now after this change is applied.

@gherceg
Copy link
Contributor

gherceg commented Jun 19, 2024

Feels a bit weird to have the same subject and body for an email, but otherwise I think it is a simple enough change that it is worth doing for the reasons you outlined above.

Copy link
Contributor

@mkangia mkangia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the redirection @kaapstorm

Also, I will be cool if you would like to drop the commit and the revert commit to keep this PR shorted with relevant commits only

@kaapstorm kaapstorm merged commit a6ff530 into master Jun 19, 2024
3 checks passed
@kaapstorm
Copy link
Contributor Author

drop the commit and the revert commit to keep this PR shorted with relevant commits only

GitHub makes this easy with "Squash and merge" :) It did squash the 3rd and 4th commits too, but I think that's okay.

@kaapstorm kaapstorm deleted the nh/empty_body branch June 19, 2024 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants