如何通过Power Automate发送邮件时保留.txt文件的文本格式?
解决Power Automate提取TXT文件邮件正文丢失格式问题
问题原因
TXT文件的换行、列表等格式仅为纯文本符号,邮件正文默认解析时不会识别这些标记,导致格式丢失,需将纯文本转换为邮件支持的HTML格式。
具体解决步骤
- 添加文本格式转换操作
在「获取文件内容」之后,依次添加多个「替换」操作:- 替换段落空行:将
\n\n替换为<p></p>,用于区分不同段落 - 替换单行换行:将
\n替换为<br>,保留行内换行 - 转换列表格式:将
\n -替换为\n<li>,再在列表块的首尾分别添加<ul>和</ul>(可通过额外替换操作实现,比如对包含<li>的文本块包裹标签)
- 替换段落空行:将
- 设置邮件为HTML格式
在发送邮件的操作中,将处理后的文本填入「正文」字段,同时选择邮件格式为HTML(不要选纯文本或富文本)
转换示例
原TXT内容:
Q: What is global warming? A: Since the Industrial Revolution, the global annual temperature has increased in total by a little more than 1 degree Celsius, or about 2 degrees Fahrenheit. - Between 1880—the year that accurate recordkeeping began—and 1980, it rose on average by 0.07 degrees Celsius (0.13 degrees Fahrenheit) every 10 years.
转换后的HTML内容:
Q: What is global warming?<br> A: Since the Industrial Revolution, the global annual temperature has increased in total by a little more than 1 degree Celsius, or about 2 degrees Fahrenheit.<p></p> <ul> <li>Between 1880—the year that accurate recordkeeping began—and 1980, it rose on average by 0.07 degrees Celsius (0.13 degrees Fahrenheit) every 10 years.</li> </ul>
内容的提问来源于stack exchange,提问作者MSM
相关产品推荐
相关产品推荐

