cli-microsoft365
cli-microsoft365 copied to clipboard
send email with multiline body from cli
Priority
Critical functionality
Description
I want to send a long enail with multiline body and it seems klunky that its asking for for the string to be passed inside the cli. I'm not sure how to do this (definitely not a cross-shell way). Can we please pass the path to a text file instead?
Thanks.
Steps to reproduce
NA
Expected results
NA
Actual results
NA
Diagnostics
No response
CLI for Microsoft 365 version
latest
nodejs version
latest
Operating system (environment)
Windows
Shell
PowerShell
cli doctor
No response
Additional Info
No response
Hey @thisismygitrepo, when you're using PowerShell you can easily do the following when you want to send a mail with a large body:
$mailMessage = "
Hi there,
Lorem ipsum dolor sit amet. Et suscipit eaque hic saepe ipsam est doloribus magni et veniam aliquid et maiores nihil. Et corrupti sapiente et rerum asperiores est mollitia asperiores. Ut quia laboriosam est cumque earum et quasi voluptas. Qui consequatur distinctio eos officia earum et placeat provident rem voluptatem optio qui mollitia voluptas hic dignissimos voluptatem qui omnis architecto.
Id illo quia non asperiores pariatur sed consequatur deserunt. Sit internos exercitationem aut eius consequatur ea voluptatibus omnis ut ipsa voluptatibus. Et cupiditate accusantium qui quia dolor est perferendis fugiat?
Rem consequatur sunt nam fuga consequuntur qui amet dolor? Quo voluptatem voluptate qui distinctio nostrum vel reprehenderit placeat ut obcaecati vitae. Qui nesciunt laboriosam et molestiae voluptatem id temporibus voluptatibus vel fugit facilis ad vero autem ut nesciunt eius vel voluptatem facere. Non inventore perspiciatis qui iste voluptate At molestiae odit qui aperiam blanditiis ut accusantium magnam?
Kind Regards,
Your IT Company
"
m365 outlook mail send --to "[email protected]" --subject "Mail subject" --bodyContents $mailMessage
Would this help in your scenario?
I remember a question like this a few months ago about Planner tasks. There we added an extra remark to help people write multi-line descriptions. Could you try the approach there @thisismygitrepo? https://pnp.github.io/cli-microsoft365/cmd/planner/task/task-add#remarks
It would make sense to add the same remark to the outlook mail send
command.
@Jwaegebaert environment variables workaround is okay, but I really wanted a cross-shell solution since the tool is cross-platform. For instance, I tried it inside a Python shell and it didn't preserve the text.
@milanholemans
I'm not sure what you meant by remarks, I had a look and you might wanted to refer to description
its still klunky as it asks people to use this character for escape if you are in shell x
and that if you are in y
etc.
I think path to text file would be a radical cross-shell solution.
Thanks.
@milanholemans I'm not sure what you meant by remarks, I had a look and you might wanted to refer to
description
its still klunky as it asks people to use this character for escape if you are in shell
x
and that if you are iny
etc.I think path to text file would be a radical cross-shell solution.
Thanks.
Yes, it is always shell dependent. We have zero control over that. Each shell has its characteristics, and all the shell magic already happened before CLI for Microsoft 365 received the values. Providing a file path where the text is stored will indeed be a universal solution, but why exactly do you want a cross-shell solution? You usually just run your script in only one shell, right?
Have you tried passing the email contents from a file using the @
token? https://pnp.github.io/cli-microsoft365/user-guide/using-cli/#passing-complex-content-into-cli-options
@waldekmastykarz
OMG this is a hidden secret. I just tried --bodyContent @file.md
and it worked!
Ummm, unfortunately, by typing m365 outlook mail send --help
You would think that this encompasses all possible things to be done and its now apparent to me that this is positively misleading. I think some hint therein would help.
Thank you.
I say let's leave this one open and use this as an opportunity to improve our docs for this command
https://pnp.github.io/cli-microsoft365/cmd/outlook/mail/mail-send
To make it clearer that you may use complex objects form a file. Although we have already this example in the docs for this command:
'Send an HTML email to the specified email address loading email contents from a file on disk'
m365 outlook mail send --to [email protected] --subject "DG2000 Data Sheets" --bodyContents @email.html --bodyContentType HTML
It seem to be not enough so I propose the following:
- let's include in the remarks section of this command additional info about referencing files and adding a link to this section: https://pnp.github.io/cli-microsoft365/user-guide/using-cli/#passing-complex-content-into-cli-options
- let's add an additional example showing how this may be done with different set of options
@pnp/cli-for-microsoft-365-maintainers any feed?
Good suggestion @Adam-it. While using the @-token is CLI-wide, it's relevant to some commands more than others. Having a specific example and call out where relevant would help raise awareness of it.