Chinaunix

标题: send email [打印本页]

作者: wzi-linux    时间: 2009-08-20 12:00
标题: send email
package com.wm.affnet.util ;
import java.io.*;
import java.net.*;
public class SendEmail {
   public static void messageSend (String senderId, String receiverId, String subjectText, String emailText)
   {
     Socket sock = null ;
     BufferedReader dis = null;
     PrintStream ps = null;
     try
     {
     InetAddress in = InetAddress.getByName(Constants.SMTP_SERVER);
     sock = new Socket(in, Constants.SMTP_PORT);
     dis = new BufferedReader( new InputStreamReader(sock.getInputStream()));
     ps = new PrintStream( sock.getOutputStream());
     ps.println("mail from: " + senderId);
     System.out.println( dis.readLine() );
     ps.println("rcpt to: " + receiverId);
     System.out.println( dis.readLine() );
     ps.println("data");
     ps.println("Subject: " + subjectText);
     System.out.println( dis.readLine() );
     ps.println(emailText);
     ps.println(".");
     System.out.println( dis.readLine() );
     ps.flush();
     sock.close();
     }
     catch(IOException e) {
        e.printStackTrace() ;
     }
     finally {
        try {
           ps.flush() ;
           sock.close() ;
        }
        catch(IOException e) {
           e.printStackTrace() ;
        }
     }
   }
}


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/103458/showart_2032711.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2