gpt4 book ai didi

java - String.format 的新行适用于控制台,但不适用于电子邮件

转载 作者:行者123 更新时间:2023-12-01 11:37:21 25 4
gpt4 key购买 nike

这就是我设置的属性

props.setProperty(EmailSender.MAIL_BODY,
"This is an automated email.%nZip Path: %s\nAdditional Text: %s\nThank you.");

我用它作为

  private String generateEmailBody(final EmailRequest diagnosticRequest) {
final String bodyTemplate = getExistingProperty(MAIL_BODY);
return String.format(bodyTemplate, diagnosticRequest.getZipFilePath(),
diagnosticRequest.getTextFromCustomer());
}

当我运行测试时,我在控制台上看到如下

Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is an automated email.
Zip Path: zipPath
Additional Text: text
Thank you.
.

但是当我收到电子邮件时,我将其视为

This is an automated email. Zip Path: zipPath Additional Text: text Thank you.

为什么不保留换行符?

我什至尝试了%n%n%n,但没有任何效果

最佳答案

您的内容类型是 Content-Type: text/html; charset=us-ascii

这意味着 \n%n在 HTML 渲染空间期间将不起作用,并且新行将被忽略(至少是大多数新行),将新行字符替换为 <br> - 这是 html 中的新行

另一个解决方案是将您的文本包含到<pre>....</pre>中标签,这将保留原始格式

当然,您可以将内容类型更改为 text/plain也是

关于java - String.format 的新行适用于控制台,但不适用于电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29835882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com