Библиотека для отправки почты по смтп
Ктото может откомпилировать пот MP вот эту библиотеку? Исходник подогнан под Mp уже
import javax.microedition.lcdui.Command.*;
import javax.microedition.lcdui.CommandListener.*;
import javax.microedition.midlet.MIDlet.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import java.io.*;
import java.util.*;
public class Lib_mylib{
public static int sendmail(String smtp, String from, String to, String subject, String msg)
{
SocketConnection sc;
InputStream is;
OutputStream os;
sc=null;
is=null;
os=null;
try {
sc = (SocketConnection) Connector.open("socket://"+smtp+":25");
is = sc.openInputStream();
os = sc.openOutputStream();
os.write(("HELO there" + "\r\n").getBytes());
os.write(("mail FROM: "+ from +"\r\n").getBytes());
os.write(("RCPT TO: "+ to + "\r\n").getBytes());
os.write("DATA\r\n".getBytes());
// stamp the msg with date
os.write(("Date: " + new Date() + "\r\n").getBytes());
os.write(("From: "+from+"\r\n").getBytes());
os.write(("To: "+to+"\r\n").getBytes());
os.write(("Subject: "+subject+"\r\n").getBytes());
os.write((msg+"\r\n").getBytes()); // message body
os.write(".\r\n".getBytes());
os.write("QUIT\r\n".getBytes());
// debug
StringBuffer sb = new StringBuffer();
int c = 0;
while (((c = is.read()) != -1) )
{
sb.append((char) c);
}
}
catch(IOException e)
{return 1;}
finally
{
try
{
if(is != null)
{is.close();}
if(os != null)
{os.close();}
if(sc != null)
{sc.close();}
}
catch(IOException e)
{
e.printStackTrace();
return 0;
}
}
return 1;
}
}
|