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

Make SMTP notify send images as attachments if html is disabled #93562

Merged
merged 1 commit into from Nov 23, 2023

Conversation

aptalca
Copy link
Contributor

@aptalca aptalca commented May 25, 2023

Breaking change

SMTP integration will send images as attachments to a plain text email instead of html in-line when the html field is not set. Previous behavior was to send all images as html in-line even when the html field was not set. To continue sending images as in-line, please set the optional html field and include the images as <img src="cid:image_name.ext"> within the html block as described in the docs: https://www.home-assistant.io/integrations/smtp/#usage

Proposed change

Current behavior:

  1. Plain text message (no html or images defined), is sent as plain text
  2. Plain text message with images defined (no html defined) is sent as html with images in-line
  3. Messages with html defined are sent as html with images in-line (if any)

Proposed behavior:

  1. Plain text message (no html or images defined), is sent as plain text (No change)
  2. Plain text message with images defined (no html defined) is sent as plain text with images as separate attachments
  3. Messages with html defined are sent as html with images in-line (if any) (No change)

Only proposed change is to the second type listed above. Currently, if the user drafts a plain text message, but adds an image, it is force converted to html and sent that way. That is not the user's intention as they could have drafted an html message if that were the intention. This change respects the user's choice with regards to plain text vs html.

I personally consider this a bugfix, because currently a plain text email is force converted to html. Most notable issue it causes is when we try to use an email-sms gateway to send a text message to a cell phone (ie. email to 5555555555@msg.fi.google.com). Without an image, email is sent plain text and is successfully delivered to the mobile device as a text/sms message. With an image, the mobile device displays the message body as raw html, and the inline images are entirely missing.

With the proposed changes, a plain text email with images get delivered to the mobile device as a proper plain text mms, along with the pictures as mms attachments.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hi @aptalca

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@davet2001
Copy link
Contributor

@aptalca I think it would be helpful to get consensus on whether your proposal is preferred behaviour.

It looks like this feature was added way back in #2738 by @partofthething. So might be worth reaching out to see if there was another reason for the original choice.

I expect many users don't realise that inline images mean an email is html, so this change might force them to

  1. Edit YAML
  2. learn basic html
    ...in order to restore previous behaviour.

If that's the case an option flag for inline images might be better?

@aptalca
Copy link
Contributor Author

aptalca commented Jun 3, 2023

Thanks @davet2001

It looks like when the image attachment functionality was PRed in, there was no support for html emails. It was all plain text. So it seems the decision of sending them as inline html was just a personal choice by the dev. There was no plain text vs html choice given to the user.

Later, when html was added as an option to the integration, the image addition forcing plain text to html probably should have been changed as it became problematic. Because at that point plain text vs html became a deliberate choice given to the users, and the forced html behavior goes against that choice.

As far as consensus goes, not sure how to get that. This integration does not have a maintainer and apart from a few forum posts asking how to add images as attachments rather than inline, that end with no, you can't do that, there hasn't been any discussion that I can see anywhere. I feel like this PR is just going to sit for a long time. Please let me know if you have any ideas. Should I try discord?

@davet2001
Copy link
Contributor

Discord or user forums could help.

https://analytics.home-assistant.io/integrations/ gives the approx number of people using this integration (currently >=3536).

I think there's quite a high chance that some of them would not want the behaviour to change.

If it did change, I suggest you would need to provide some instructions on how to restore old behaviour. For example, if a user does want inline images, what should they change their YAML to?

  • To avoid this being a user facing problem you could make it selectable and make HTML the default for existing users.

But given that new YAML configuration options are no longer allowed, the first step might be to convert it to be set up via the UI, then make the change. This is clearly more work and probably not what you were hoping for.

I genuinely don't know what the use cases are. It could be that no one wants html. But my experience is that if you change something that affects users who were already happy, they will expect immediate guidance on how to make it work like it used to.

@partofthething
Copy link
Contributor

Hi. Thanks for reaching out. I am still using this, and am totally fine with this change. Seems like an improvement to me, and I'll have no problem adjusting my config as necessary.

@aptalca
Copy link
Contributor Author

aptalca commented Jun 3, 2023

I genuinely don't know what the use cases are. It could be that no one wants html. But my experience is that if you change something that affects users who were already happy, they will expect immediate guidance on how to make it work like it used to.

That's a good point. I'll try and come up with a way to maintain the current behavior by default and add a flag for selecting attachments vs inline.

@github-actions
Copy link

github-actions bot commented Sep 1, 2023

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@github-actions github-actions bot added the stale label Sep 1, 2023
@aptalca
Copy link
Contributor Author

aptalca commented Sep 2, 2023

I gave this more thought and I'm personally not in favor of keeping the current behavior because it would be very confusing. The email should be html when the user selects and inputs html. If not, it should be plain text. That's my opinion.

In any case, that's not a coding decision, but a behavior decision so it's not really up to me. HA team will have to decide since there is no maintainer for this core integration.

Thanks

@github-actions github-actions bot removed the stale label Sep 2, 2023
@davet2001
Copy link
Contributor

davet2001 commented Sep 4, 2023

Ok, I suggest adding a description of what the user has to do if they want the images to stay inline. This can be added to the PR description. That can then be included in the breaking changes in the release notes.

I think an example YAML snippet is needed with HTML, ready for copy/paste.

@aptalca
Copy link
Contributor Author

aptalca commented Sep 21, 2023

thanks @davet2001
Updated the PR description to add the breaking change, along with a link to the docs page that includes a detailed example.

Also improved attachment handling where it could add double headers if the file's MIME type could not be determined as image.

@davet2001
Copy link
Contributor

@aptalca The CI is failing, please can you check and run it locally?

@aptalca
Copy link
Contributor Author

aptalca commented Sep 25, 2023

@aptalca The CI is failing, please can you check and run it locally?

Fixed formatting. Thanks for the heads up.

@davet2001 davet2001 added the second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. label Sep 30, 2023
Copy link
Contributor

@davet2001 davet2001 left a comment

Choose a reason for hiding this comment

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

This looks good to me, the change is as described and the updated documentation is accurate.

Requested 2nd opinion to make sure others are happy with the user impact.

@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Oct 6, 2023
update smtp test to detect content_type for plain txt + image
Copy link
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

The change makes perfect sense and the behavior more logical.
Thanks @aptalca 👍

@emontnemery emontnemery changed the title smtp notify: send images without html as attachments Make SMTP notify send images as attachments if html is disabled Nov 23, 2023
@emontnemery emontnemery merged commit a1f7f89 into home-assistant:dev Nov 23, 2023
21 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking-change bugfix cla-signed integration: smtp Quality Scale: No score second-opinion-wanted Add this label when a reviewer needs a second opinion from another member. small-pr PRs with less than 30 lines. smash Indicator this PR is close to finish for merging or closing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants