|
Sending e-mail from a mobile device |
|
|
This tip demonstrates a method of sending a mail from a
handset. Wireless portals support many of the same applications as
Internet portals. For example they provide messaging services, which
includes electronic mail. So this tip in J2ME may be very helpful for
developers who want to implement these type of services.
void sendMail()
{
SocketConnection sc=null;
InputStream is=null;
OutputStream os=null;
//Login to mail server
try {
byte b[]=new byte[200];
int total=0;
sc = (SocketConnection)
Connector.open("socket://"+servAdd+":110");
is = sc.openInputStream();
os = sc.openOutputStream();
os.write(("USER
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
").getBytes());
total=is.read(b);
response+=new String(b,0,total);
os.write(("PASS 123\r\n").getBytes());
total=is.read(b);
response+=new String(b,0,total);
// Sending mail
sc = (SocketConnection)Connector.open("socket://"+serverAdd+":25");
is = sc.openInputStream();
os = sc.openOutputStream();
os.write(("HELO there" + "\r\n").getBytes());
os.write(("MAIL FROM:
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
").getBytes());
os.write(("RCPT TO:
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
").getBytes());
os.write("DATA\r\n".getBytes());
os.write(("From:
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
").getBytes());
os.write(("To:
This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
").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());
} catch(Exception e){}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.