Hi, Tom

for ur Convenience u can use the code below

import java.util.*;
import java.net.*;
import java.io.*;

public class SMTPSender
{
        /**
         * Hashtable will hold the rejected recipients
addresses
         */
        Hashtable htRejectedRelay = new Hashtable();
        
        /**
         * Send message to destination smtphost
         * @author Sandiep U. Sharma
(http://www.infosoftin.com)
         * @smtphost: SMTP Host address
         * @From: Sender email address
         * @vt: Vector containing recipients e-mail addresses
         * @mmess: Byte array containing message (include
<CRLF>.<CRLF> characters)
         */                                                                            
           
        public void sendMessage(String smtphost,String From,
Vector vt, byte[] mmess)
        {
                //System.out.println("smtphost:"+smtphost+"
From:"+From+" Rcpt:"+vt.toString());
                //System.out.println("Connecting to :"+smtphost);
                Socket sk=null;
                DataInputStream din=null;
                DataOutputStream dout=null;
                try { 
                        // connect to smtp host and initialize I/O streams
                        sk = new Socket(smtphost,25);
                        System.out.println("Connected");
                        String strresp;
                        din = new DataInputStream(sk.getInputStream());
                        dout = new DataOutputStream(sk.getOutputStream());
                        strresp = din.readLine();
                        System.out.println("S:"+strresp);
                        if (strresp.startsWith("220"))
                                dout.writeBytes("helo <server>\r\n");   //Replace
server with hostname
                        else {
                                System.out.println("Error :"+strresp);
                                recipientRejected(vt.toString(),strresp);              
         
                                return;
                        }               
                        strresp = din.readLine();
                        System.out.println("S:"+strresp);       
                        if (strresp.startsWith("250"))
                        {
                                dout.writeBytes("mail from:<"+From+">\r\n");
                        }
                        else {
                                System.out.println("Error :"+strresp);
                                recipientRejected(vt.toString(),strresp);
                                return;
                        }
                
                        strresp = din.readLine();
                        System.out.println("S:"+strresp);
                
                        if (strresp.startsWith("250"))
                        {
                                for (int i = 0;i<vt.size();i++)
                                {
                                        String strrcpt = (String) vt.elementAt(i);
                                        dout.writeBytes("rcpt to:<"+strrcpt+">\r\n");
                                        strresp = din.readLine();
                                        //System.out.println("S:"+strresp);
                                        if (!strresp.startsWith("250")) {
                                                recipientRejected(strrcpt,strresp);
                                        }                               
                                }                       
                        }
                        else 
                        {
                                System.out.println("Error :"+strresp);
                                recipientRejected(vt.toString(),strresp);              
         
                                return;
                        }
                        dout.writeBytes("data\r\n");
                        strresp = din.readLine();
                        System.out.println("S:"+strresp);

                        if (strresp.startsWith("354"))
                        {
                                dout.write(mmess);
                        }
                        else {
                                System.out.println("Error :"+strresp);
                                recipientRejected(vt.toString(),strresp);              
         
                                return;
                        }               
                        strresp = din.readLine();
                        System.out.println("S:"+strresp);               
                        dout.writeBytes("quit\r\n");
                } catch (Exception ioe) {
                        System.out.println("I/O error while relaying
mail:"+ioe.toString());
                        recipientRejected(vt.toString(),ioe.getMessage());
                        return;
                }
                try {
                        din.close();
                        dout.close();
                        sk.close();
                } catch (Exception ioe) {/* log this exception */}
        }

        private void recipientRejected(String
strrecipient,String strReason)
        {
                // do somethis here for the rejected relayed
recipients
                System.out.println("\t recipient rejected
"+strrecipient);
                htRejectedRelay.put(strrecipient,strReason);
        }
}

best Regards
Sandiep U. Sharma, CTO Infosoft
www.infosoftin.com

__________________________________________________
Do You Yahoo!?
Yahoo! Tax Center - online filing with TurboTax
http://taxes.yahoo.com/

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to