简体   繁体   English

如何在使用 Java 发送电子邮件时防止调试代码?

[英]How to prevent debug code while sending an email using Java?

I am using a java program which sends an email to the addresses specified.我正在使用一个 java 程序,它向指定的地址发送电子邮件。 The program works fine but it produces a lot of debug code in my console which is not needed.该程序运行良好,但它在我的控制台中产生了大量不需要的调试代码。 The statements that are producing the debug code are:产生调试代码的语句是:

-------
 Session session = Session.getInstance(mailProperties, auth);
---
 transport = session.getTransport("smtp");
----
  transport.sendMessage(message, message.getAllRecipients());

Is there any way to prevent this?有什么办法可以防止这种情况吗? Btw, I am using mail.jar and activation.jar for sending the email.顺便说一句,我使用 mail.jar 和 activation.jar 来发送电子邮件。

Sample Debug Code:示例调试代码:

250-SIZE
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-X-ANONYMOUSTLS
250-AUTH NTLM
250-X-EXPS GSSAPI NTLM
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250-XEXCH50
250-XRDST
250 XSHADOW
DEBUG SMTP: Found extension "SIZE", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "DSN", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "X-ANONYMOUSTLS", arg ""
DEBUG SMTP: Found extension "AUTH", arg "NTLM"
DEBUG SMTP: Found extension "X-EXPS", arg "GSSAPI NTLM"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "BINARYMIME", arg ""
DEBUG SMTP: Found extension "CHUNKING", arg ""
DEBUG SMTP: Found extension "XEXCH50", arg ""
DEBUG SMTP: Found extension "XRDST", arg ""
DEBUG SMTP: Found extension "XSHADOW", arg ""
DEBUG SMTP: use8bit false

Thanks in Advance.提前致谢。

From JavaMail API docs来自JavaMail API 文档

public void setDebug(boolean debug) public void setDebug(布尔调试)

Set the debug setting for this Session.设置此会话的调试设置。

Since the debug setting can be turned on only after the Session has been created, to turn on debugging in the Session constructor, set the property mail.debug in the Properties object passed in to the constructor to true.由于只有在创建 Session 后才能打开调试设置,因此要在 Session 构造函数中打开调试,请将传入构造函数的 Properties 对象中的属性 mail.debug 设置为 true。 The value of the mail.debug property is used to initialize the per-Session debugging flag. mail.debug 属性的值用于初始化每个会话的调试标志。 Subsequent calls to the setDebug method manipulate the per-Session debugging flag and have no affect on the mail.debug property.对 setDebug 方法的后续调用操作每个会话的调试标志并且对 mail.debug 属性没有影响。

Parameters: debug - Debug setting参数: debug - 调试设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM