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() ;
}
}
}
}
阅读(389) | 评论(0) | 转发(0) |