這裏的時候,在控制檯上禁用Java郵件跟蹤是我用來發送電子郵件的代碼:如何發送電子郵件
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 < < < < < <
>>>>>發送數據AUTH LOGIN < < < < < <
>>>>>發送數據XXXXXXXXXXXXXXXXXXXX < < < < < <
>>>>>發送數據XXXXXXXXXXXXXX < < < < < <
>>>>>發送數據來自:< < < < < <
>>>>>發送數據RCPT TO:< < < < < <
>>>>>發送數據DATA < < < < < <
>>>>>發送數據< < < < < <
>>>>>發送數據。 < < < < < <
>>>>>發送數據QUIT < < < < < <
如何禁用此輸出?我的catalina.out增長太快了。 Setdebug(false)方法不能解決我的問題。
你已經嘗試過'session.setDebug(false)'? – 2013-02-19 11:21:21
或者你是否使用屬性'-Dmail.debug = true'開始你的應用程序? - http://www.oracle.com/technetwork/java/faq-135477.html#debug – Augusto 2013-02-19 11:25:34
session.setDebug(false)不能解決我的問題。我不在我的tomcat應用中使用-Dmail.debug = true。 – user2086740 2013-02-19 11:36:05