gpt4 book ai didi

java - 发送电子邮件时如何在控制台上禁用 java 邮件跟踪

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:02:39 28 4
gpt4 key购买 nike

这是我发送电子邮件的代码:

    public void sendMail() 
{
try
{
// Propiedades de la conexión
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.port", SMTP_PORT);
props.put("mail.smtp.auth", "true");

Authenticator auth = new SMTPAuthenticator();
Session mailSession = Session.getDefaultInstance(props, auth);

Transport transport = mailSession.getTransport();

MimeMessage message = new MimeMessage(mailSession);
Multipart multipart = new MimeMultipart("alternative");

BodyPart text = new MimeBodyPart();
text.setContent(mailMessage,"text/html; charset=UTF-8");

multipart.addBodyPart(text);

message.setContent(multipart);

if(friendlyName != null){
//String send = friendlyName + " <" + sender + ">";
message.setFrom(new InternetAddress(sender, friendlyName));
}else{
message.setFrom(new InternetAddress(sender));
}

message.setSubject(subject,"UTF-8");
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(receiver));

transport.connect();
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
transport.close();


}catch (Exception e) {
// TODO: handle exception
}

}

当我发送电子邮件时,我在控制台(或 catalina.out)上得到了这个输出:

>>>>>发送数据EHLO xxxxxx<<<<<<

>>>>>发送数据授权登录<<<<<<

>>>>>发送数据xxxxxxxxxxxxxxxxxxxx<<<<<<

>>>>>发送数据xxxxxxxxxxxxxx<<<<<<

>>>>>发送数据邮件来自:<<<<<<

>>>>>发送数据 RCPT 至:<<<<<<

>>>>>发送数据DATA<<<<<<

>>>>>发送数据<<<<<<

>>>>>发送数据.<<<<<<

>>>>>发送数据退出<<<<<<

如何禁用此输出?我的 catalina.out 增长太快了。 Setdebug(false) 方法没有解决我的问题。

最佳答案

在 Spring ,这对我有用:

    <property name="javaMailProperties">
<props>
<prop key="mail.transport.protocol">smtp</prop>
<prop key="mail.smtp.auth">false</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.debug">false</prop>
</props>
</property>

使用 1.4.7+ 版本测试

关于java - 发送电子邮件时如何在控制台上禁用 java 邮件跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14956063/

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