Log4j SMTPappender 与 HTML 邮件

发布于 2024-09-18 10:27:10 字数 93 浏览 3 评论 0原文

我想使用 log4j 并以 HTML 格式发送电子邮件(使用 SMTP Appender)。 log4j 中是否可以开箱即用。

如果是这样,请指出正确的例子

I would like to use log4j and send email in HTML format (Using SMTP Appender). Is it possible in log4j out of the box.

If so please point me to right examples

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戏舞 2024-09-25 10:27:10

Logback 提供了将日志格式化为 HTML 的布局。将其与 SMTPAppender 结合起来将以 HTML 格式发送电子邮件。

http://logback.qos.ch/manual/layouts.html#ClassicHTMLLayout

直接引用页面:

HTMLLayout常用于
与 SMTPAppender 结合使用,以便
外发电子邮件的格式令人愉快
在 HTML 中。

您甚至可以轻松获取源代码并对其进行修改,以满足您的需求。

http://logback.qos.ch/xref/ ch/qos/logback/classic/html/HTMLLayout.html


They provide the following code to initilaize the appender:

 <appender name="SMTP" class="ch.qos.logback.classic.net.SMTPAppender">
    <layout class="ch.qos.logback.classic.html.HTMLLayout">
      <pattern>%relative%thread%mdc%level%class%msg</pattern>
    </layout>
    <From>[email protected]</From>
    <SMTPHost>mail.domain.net</SMTPHost>
    <Subject>LastEvent: %class - %msg </Subject>
    <To>[email protected]</To> 
  </appender>


I hope that helps in some way,

-g男性

Logback provides a Layout that formats the logs as HTML. Combining that with an SMTPAppender would send email in HTML format.

http://logback.qos.ch/manual/layouts.html#ClassicHTMLLayout

Direct quote from the page:

The HTMLLayout is often used in
conjunction with SMTPAppender so that
outgoing email is pleasantly formatted
in HTML.

You could even take the source code and modify it, pretty easily, to suit your needs.

http://logback.qos.ch/xref/ch/qos/logback/classic/html/HTMLLayout.html


They provide the following code to initilaize the appender:

 <appender name="SMTP" class="ch.qos.logback.classic.net.SMTPAppender">
    <layout class="ch.qos.logback.classic.html.HTMLLayout">
      <pattern>%relative%thread%mdc%level%class%msg</pattern>
    </layout>
    <From>[email protected]</From>
    <SMTPHost>mail.domain.net</SMTPHost>
    <Subject>LastEvent: %class - %msg </Subject>
    <To>[email protected]</To> 
  </appender>


I hope that helps in some way,

-gMale

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文