Socket Connection and Sending Emails in J2ME Suggestions
Hi Sun Community:
I'm developing an application that acts as a mail client but just to send the emails. I'm using the Sun Java Wirelles Toolkit version 2.5 to write the application.
What I'm doing is opening a socket connection and then sending to any smtp server a set of commands that he need in order to receive the email, the problem is that sometimes the email dont arrive and I need to run the code two or three time. I was wondering if there is a way to improve this code or make a connection in a secure way.
If someone can send me some code would be great, thanks.
This is just a piece about what I got until now:
SocketConnection sc = (SocketConnection) Connector.open("socket://"+smtpServerAddress+":25");
InputStream is = sc.openInputStream();
OutputStream os = sc.openOutputStream();
os.write(("HELO" +"\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());
.
.
.
[1307 byte] By [
jonhya] at [2007-11-27 11:16:27]

# 1
Hi johny
I think your problem (I may be wrong though) is to do with your login to the mail server i.e. auth login or auth plain etc ...
As I've mentioned previously the bes way to test this is telnet to the correct port using the command prompt ie.
C:\>telnet mailserver portnumber
and manually try to send your mail, from this you will see exactly where your problem lies.
Regards
Steve
# 2
Thanks Steve;
I understand what you said I already tried all the commands using telnet and it happens the same, sometimes it works but sometimes it doesn't. I was wondering if there is another way to do this because I dont want to use any java servlet and neither an script on a web page.
That's what I am asking this because in theory it should work for any smtp server but something its wrong and I dont know what it is.
thanks
jonhya at 2007-7-29 14:19:13 >

# 3
Hi johny
The initial example I sent you worked 100%, I used it to test if a SMTP server was up at least 3 times a day for about 8 months.
The only thing that concerned me about it was, I had to put in the encrypted user name and password, which I got by sniffing port 25 while sending an email, into the code for the auth login (fortunately it never changed).
If your SMTP sever does not require authentication, I see no reason why it did not work.
Regards
Steve