Package testxml;
Import testemail .*;
Import java. Io .*;
Import org. dom4j. Io .*;
Import org. dom4j. Document;
Import org. dom4j. Io. outputformat;
Import org. dom4j. Io. saxreader;
Import org. dom4j. Io. xmlwriter;
Import org. xml. Sax. inputsource;
Public class prettyprint {
Public static void main (string [] ARGs ){
Try {
String body = "<A> <B> ASD </B> <C> asgf </C> </a> ";
// File = new file ("FILENAME ");
Bytearrayinputstream FIP = new bytearrayinputstream (body. getbytes ());
Inputsource is = new inputsource (FIP );
// Bytearrayinputstream FIP = new bytearrayinputstream (body. getbytes ());
// Fileoutputstream F = new fileoutputstream (FIP );
// F. Write (body. getbytes ());
Saxreader = new saxreader ();
Document Doc = saxreader. Read (is );
Outputformat format = outputformat. createprettyprint ();
Format. setencoding ("UTF-8 ");
String out;
Bytearrayoutputstream bout = new bytearrayoutputstream ();
Xmlwriter writer = new xmlwriter (bout, format );
Writer. Write (DOC );
Writer. Close ();
Byte [] B = bout. tobytearray ();
Stringbuilder sb = new stringbuilder ();
For (INT I = 0; I <B. length; I ++ ){
SB. append (char) B [I]);
}
Javamail163.endemail (sb. tostring ());
System. Out. println (sb. tostring ());
} Catch (exception ex ){
Ex. printstacktrace ();
System. Out. println ("Err ");
}
}
}
Package testemail;
Import java. util .*;
Import javax. Mail. Internet .*;
Import javax. Mail .*;
Public class javamail163 {
Static class mailauthenticator extends javax. Mail. authenticator {
String authenname;
String authenpass;
Public mailauthenticator (string authenname, string authenpass ){
Super ();
This. authenname = authenname;
This. authenpass = authenpass;
}
Public javax. Mail. passwordauthentication getpasswordauthentication (){
Return new javax. Mail. passwordauthentication (authenname, authenpass );
}
}
Public static void endemail (string context) throws addressexception,
Messagingexception {
Properties mailpro = new properties ();
// Mailauthenticator MA = new mailauthenticator ("peng_xu", "161523px ");
Mailpro. setproperty ("mail. SMTP. Host", "smtp.vanceinfo.com ");
// Mailpro. setproperty ("mail. SMTP. Auth", "true ");
Session session = session. getdefaultinstance (mailpro );
Session. setdebug (true );
Mimemessage MSG = new mimemessage (session );
MSG. setfrom (New internetaddress ("jessepengxu@163.com "));
MSG. setrecipient (message. recipienttype.,
New internetaddress ("jessepengxu@163.com "));
MSG. setsubject ("test sending email !!! ");
MSG. settext (context );
Transport. Send (MSG );
}
}