When I add something to Drafts using the maildrop from my work email account, it always has a GDPR ‘banner’ at the bottom. This is true for any email sent from my work email account, and is centrally managed and so not something I can turn off.
At the moment, I have to manually remove this block of text every time I email something to Drafts.
I believe that there is a way to use scripting to automatically (or at least create an action) that will do this for me. The text is the same every time.
I’ve tried looking it up online and found that in JavaScript there is the replace() function. However, having never used JavaScript before I’m getting stuck.
The code that I’m trying to run is:
let result = text.replace("************************************************************************************** ******************************
This message may contain confidential information. If you are not the intended recipient please:
i) inform the sender that you have received the message in error before deleting it; and
ii) do not disclose, copy or distribute information in this e-mail or take any action in relation to its content (to do so is strictly prohibited and may be unlawful).
Thank you for your co-operation.", "");
However, when I run this I get the error:
Script Error: SyntaxError: Unexpected EOF
Line number: 1, Column undefined
Any help or advice would be greatly appreciated!
Literal string values wrapped in double quotes cannot be multiple lines in JavaScript. You would have to escape the line feeds a \n
. Or, you can use backticks to make a multi-line template string, like:
let result = text.replace(`************************************************************************************** ******************************
This message may contain confidential information. If you are not the intended recipient please:
i) inform the sender that you have received the message in error before deleting it; and
ii) do not disclose, copy or distribute information in this e-mail or take any action in relation to its content (to do so is strictly prohibited and may be unlawful).
Thank you for your co-operation.`, "");
I’m still having difficult with this I’m afraid.
The full email footer is:
************************************************************************************** ******************************
This message may contain confidential information. If you are not the intended recipient please:
i) inform the sender that you have received the message in error before deleting it; and
ii) do not disclose, copy or distribute information in this e-mail or take any action in relation to its content (to do so is strictly prohibited and may be unlawful).
Thank you for your co-operation.
NHSmail is the secure email, collaboration and directory service available for all NHS staff in England. NHSmail is approved for exchanging patient data and other sensitive information with NHSmail and other accredited email services.
For more information and to find out how you can switch visit [ Joining NHSmail – NHSmail Support](https://support.nhs.net/article-categories/joining-nhsmail/)
The script I have in my action is:
let result = text.replace(`************************************************************************************** ******************************
This message may contain confidential information. If you are not the intended recipient please:
i) inform the sender that you have received the message in error before deleting it; and
ii) do not disclose, copy or distribute information in this e-mail or take any action in relation to its content (to do so is strictly prohibited and may be unlawful).
Thank you for your co-operation.`, "");
But I get the error message shown in the screenshot.
I’m not great with scripting but don’t get what I’m doing wrong. Any help would be greatly appreciated!
What is your whole script? That message is saying the text
variable does not exist. That is not something Drafts would define, so it would have to be something you defined earlier in your script to be used.
If you are just trying to write this script to replace text in the content of the draft that the action is being run on, that would look like:
draft.content = draft.content.replace(`************************************************************************************** ******************************
This message may contain confidential information. If you are not the intended recipient please:
i) inform the sender that you have received the message in error before deleting it; and
ii) do not disclose, copy or distribute information in this e-mail or take any action in relation to its content (to do so is strictly prohibited and may be unlawful).
Thank you for your co-operation.`, "")
draft.update()
That’s exactly it, I was missing the drafts content bit. Thank you so much @agiletortoise