Can't send email from J2ME.

B

Boki

sc = (SocketConnection)
Connector.open("socket://"+"smpt.abcd.com"+":25");

is = sc.openInputStream();
os = sc.openOutputStream();

os.write( ("USER " + "Boki" + "\r\n").getBytes());
os.write( ("PASS " + "PASS1234" + "\r\n").getBytes());

os.write(("HELO there" + "\r\n").getBytes());
os.write(("MAIL FROM: "+ "Boki" +"\r\n").getBytes());
os.write(("RCPT TO: "+ "(e-mail address removed)" +
"\r\n").getBytes());
os.write("DATA\r\n".getBytes());
// stamp the msg with date
os.write(("Date: " + date + "\r\n").getBytes());
os.write(("From: "+"From Boki"+"\r\n").getBytes());
os.write(("To:
"+"(e-mail address removed)"+"\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());




// I can't see this email on server.... it seems never send correctly.

Could you please advice ?

Thank you very much!
Best regards,
Boki.
 
M

Martin Gregorie

Boki said:
sc = (SocketConnection)
Connector.open("socket://"+"smpt.abcd.com"+":25");

is = sc.openInputStream();
os = sc.openOutputStream();

os.write( ("USER " + "Boki" + "\r\n").getBytes());
os.write( ("PASS " + "PASS1234" + "\r\n").getBytes());

os.write(("HELO there" + "\r\n").getBytes());
os.write(("MAIL FROM: "+ "Boki" +"\r\n").getBytes());
os.write(("RCPT TO: "+ "(e-mail address removed)" +
"\r\n").getBytes());
os.write("DATA\r\n".getBytes());
// stamp the msg with date
os.write(("Date: " + date + "\r\n").getBytes());
os.write(("From: "+"From Boki"+"\r\n").getBytes());
os.write(("To:
"+"(e-mail address removed)"+"\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());




// I can't see this email on server.... it seems never send correctly.

Could you please advice ?

Thank you very much!
Best regards,
Boki.
Several reasons:

(1) No initial "From sender@host" line
(2) No blank line between the headers and the message body
(3) No "." line at the end of the message

Those should do for starters.

Why don't you use JavaMail? Its easy enough to use and free from Sun
 
N

Nigel Wade

You've opened a connection to an SMTP server (I presume it's an SMTP server
since you are connecting on port 25) but have not read the server greeting.
You've jumped straight into sending commands. Read the response, it may tell
you something useful, like your connection has been rejected.

What is this?

An SMTP conversation does not begin with USER/PASS. If you need to authenticate
you do so after the initial EHLO (not HELO, that doesn't support
authentication), and *only* if the server offers authentication as an option.
Even then it must be initiated by the AUTH command. I've never seen USER/PASS
as part of any SMTP authentication process, normally the client responds to
prompts from the server.

Further, since extended options are only offered in response to EHLO, and the
conversation is initiated with HELO, I doubt the server would offer
authentication. If it did it's broken, the 250- extended options MUST NOT
(capitalization from the RFC) be sent in response to HELO.
You need to read the response to HELO.

You need to read the response to MAIL FROM:

You need to read the response from RCPT TO:

You need to read the response from DATA.

Ignoring these responses is considered rude, and many SMTP servers will refuse
to accept a message if you don't bother to read what they had to say in
response to your input. Not reading responses is a very good indicator of a
badly written client, very often a spam engine, and a good reason to terminate
immediately, or to tar-pit the client to slow the stream of spam.

You are right, it is not sent correctly ;-)
Several reasons:

(1) No initial "From sender@host" line

That's not part of the original mail message. The line you indicate is added by
a mail delivery agent, and is the envelope sender claimed in the MAIL FROM:
SMTP command. It's not part of the message body sent by the client.

(2) No blank line between the headers and the message body

Whilst an SMTP server can look at the contents of the message it isn't required
to do so. It might do so as an anti-spam, anti-virus measure, but not normally
to enforce RFC822 message semantics. It would be very strange for an SMTP
server to reject a message because the message body didn't conform.
(3) No "." line at the end of the message

What about:

os.write(".\r\n".getBytes());

Those should do for starters.

Why don't you use JavaMail? Its easy enough to use and free from Sun

That is a valid point. The OP clearly doesn't understand SMTP.
 
B

Boki

Martin Gregorie ¼g¹D¡G
Several reasons:

(1) No initial "From sender@host" line
(2) No blank line between the headers and the message body
(3) No "." line at the end of the message

Those should do for starters.

Why don't you use JavaMail? Its easy enough to use and free from Sun

JavaMail ? support J2ME ? I am newbie ...

Could you please advice the sample code is ....

Best regards,
Boki.
 
B

Boki

since you are connecting on port 25) but have not read the server greeting.
You've jumped straight into sending commands. Read the response, it may tell
you something useful, like your connection has been rejected.

1) I am using J2ME, can't use javamail.
2) I think I was wrong here, could you please provide the sequence that
I should follow to login email server.

or is there any free email server that I can just do a test ?


Thx a lot!

Best regards,
Boki.
 
N

Nigel Wade

Boki said:
1) I am using J2ME, can't use javamail.
2) I think I was wrong here, could you please provide the sequence that
I should follow to login email server.

You need to read the RFCs, and follow the protocol.

The RFC for SMTP is 2821, and the RFC for SMTP authentication is 554.
or is there any free email server that I can just do a test ?

I have no idea. I would have thought your best bet would be your ISPs mail
server, although your ISP might begin to get suspicious at the amount of SMTP
protocol errors from your account.

If you really want to make it work why don't you setup your own SMTP server.
But, for all our sakes, don't connect it to the Internet.
 
M

Martin Gregorie

Boki said:
1) I am using J2ME, can't use javamail.
2) I think I was wrong here, could you please provide the sequence that
I should follow to login email server.
If you haven't already done so, grab a copy of RFC 2821 from
http://www.rfc-editor.org/rfcsearch.html and use it for reference.
or is there any free email server that I can just do a test ?
Its difficult to recommend anything when you don't say what OS you're
using or what's already on your local LAN, but:

- if you're running Linux, FreeBSD or a UNIX or there's one on
your LAN then there will be an SMTP MTA (server) running on it
that you can use as a target. If its another host on your LAN,
you may have to talk to its sysadmin to gain access.

- go look at the JavaMail site. There are a few SMTP MTAs,
e.g. XM Server, listed under Third Party downloads. I haven't used
any of them, so have no recommendation or opinion about them, but
being Java applications, they should run on your development system
whatever it may be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top