Import javax.mail. *; import javax.mail.internet. *; import java.util.properties; import java.util.date;
Public class sendmail {public static void main (string args []) throws exception {
// String host = "smtp.sina.com.cn"; string host = "smtp.163.com"; string from = "test@163.com"; // Sending mail string to = "GoHands @ 163. Com "; string to2 = GoHands@163.com; string username =" test "; string password =" passwd "; string filettachment =" g: // Documents and settings // aaa // my documents // my eBooks // Attachment .txt ";
// Get System Properties Properties PROPS = New Properties ();
// SETUP MAIL Server Props.Put ("mail.smtp.host", host); Props.Put ("mail.smtp.auth", "true"); // Get session session session = session.getDefaultinstance (Props) ;
// Watch the mail commands go by to the mail server session.setdebug (true);
// Define message MimeMessage message = new MimeMessage (session); message.setFrom (new InternetAddress (from)); message.addRecipient (Message.RecipientType.TO, new InternetAddress (to)); message.addRecipient (Message.RecipientType.TO New InternetAddress (TO2));
message.setSubject ( "heading"); message.setText ( "text"); // message.setContentLanguage (); // FileTypeMap FileDataSource fds = new FileDataSource (fileAttachment); //// message.setDataHandler (new DataHandler (fds ));