- 论坛徽章:
- 0
|
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 |
|