• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sending mail using servlet

 
Muhammed Salah
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi people,

i hope you can help me because i am new in network programming.

I am trying to send email from j2me to googlemail account I have 2 classes EmailMidlet (which has been tested with wireless Toolkit 2.5.2 and it works) and the second class is the servlet-class named EmailServlet:

when i call the EmailServlet, i get on the console:

Server: 220 mx.google.com ESMTP g28sm19313024fkg.21
Server: 250 mx.google.com at your service


this is the code of my EmailServlet


1.when i print "to" in EmailServlet also:


it show null on the console
2. ist this right in case of googlemail.com?



and this is my EmailMidlet:



I would be very grateful if somebody can help me.
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Check with your firewall settings, you can add an exception to port 25 there.

To do this, go to run -> type firewall.cpl -> press enter

Cheers!!!

Ujjwal B Soni
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just another cross poster.
http://discussion.forum.nokia.com/forum/showthread.php?p=521548
http://forums.sun.com/thread.jspa?threadID=5357472
 
sumanta panda
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Edit: thread hijack removed. Ask your own questions in your own topics, and be sure to post them in an appropriate forum.]
[ December 26, 2008: Message edited by: Bear Bibeault ]
 
Muhammed Salah
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you all for replay.


@ujjwal soni

i did the following:
exception:
Name:SMTP (name correct?)
PortNr: 25

nothing change

i have notice the follwing warning for the method readline() in EmailServlet:
the method readline from the typ DataInputStream is deprecated.

could it be a problem?
 
Muhammed Salah
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one quistion about transfering data between midlet-class servlet-class through DataInputStream and DataOutPutStream.

i write the following in the midlet-class:
DataOutputStream os = c.openDataOutputStream();
os.write(("to="+to).getBytes()); (where String to="myemail@googlemail.com"; )
os.write(("&subject="+subject).getBytes());
.....
....

and tried to call this in the servlet-class through the following:
request.getParameter("to");

it returns null
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Muhammed Salah:
request.getParameter("to");

it returns null
That just means there wasn't any "to" parameter in the request. Nothing to do with e-mail or DataInputStream or any of those things, the user just didn't type anything into the "to" field.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65217
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Clapham:
the user just didn't type anything into the "to" field.

That would result in an empty string, not a null. A null indicates that the text field was not part of the submitted form to begin with.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
A null indicates that the text field was not part of the submitted form to begin with.
And it appears that the posted code with DataOutputStreams is trying to do something like submitting a form. It looks like it's generating a "to" parameter, but the comments indicate the value of that parameter is something which should be URL-encoded, but isn't. And who knows? Maybe that's the wrong place to put the parameter. It's hard to tell from that fragment of code.
 
Muhammed Salah
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your reply.

i write myemail@google.com to the "to"-feld and then press send.

String to in the midlet will be overwritten through to = toField.getString();

my Problem is the the exchange of data between servlet and midlet

and the notation:
DataOutputStream os = c.openDataOutputStream();
os.write(("to="+to).getBytes());

How can i call "to" from the servlet or how can i be sure, that servlet can call "to"?
 
Srikanth Nutigattu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Muhammed Salah

Not only the "To" field but even subject and message fields are not being passed.

Solution:

In your code, remove this line

os.flush();

from the midlet. I could retrieve the fields from the servlet after that...

HTH.
[ December 28, 2008: Message edited by: Srikanth Nutigattu ]
 
Muhammed Salah
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Srikanth Nutigattu:

Solution:

In your code, remove this line

os.flush();

from the midlet. I could retrieve the fields from the servlet after that...

HTH.

[ December 28, 2008: Message edited by: Srikanth Nutigattu ][/QB]


Hi Srikanth Nutigattu

i did.

but the following print() in the servlet still return null:

out.print(request.getParameter("to"));
System.out.println(request.getParameter("to"));

the following print in the midlet returns "myEmail@googlemail.com"
System.out.println(to);
c = (HttpConnection)Connector.open(url);

i read in other forum about url-encude could be the problem.
any idea about this in case of connection.open(url)?
 
Muhammed Salah
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh i forgot = in ("to="+to).getBytes())


i solved my Problem

thank you so much you have saved me alive


now I can continue to next problem (sending email)
 
Muhammed Salah
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now i am trying to find the IOException in the send(....)-method.

i wrote the send()method in java class and started eclipse debug.

the pointer jump from the line:
while ((responseLine = is.readLine()) != null) {....

to:

catch (IOException e) {
System.err.println("IOException: " + e.getMessage());
e.printStackTrace();
}

and returns the following error:

IOException: Software caused connection abort: recv failed

java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.DataInputStream.readLine(Unknown Source)
at EmailSender.send(EmailSender.java:59)
at EmailSender.main(EmailSender.java:79)

i was researching about this error in google some people say firewall could be the problem.
i shut down my firewall and antivirus but nothing change.

any idea, what can i do?

thank you
 
Muhammed Salah
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have solved my Problem by using java mail.


I would like to thank everyone here, who tried to help me.........

Thank you so much,
thedaystar
 
firstName SecondName
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Muhammed Salah wrote:I have solved my Problem by using java mail.


I would like to thank everyone here, who tried to help me.........

Thank you so much,
thedaystar

hi brother,

i saw your post regarding email sending from j2me.
can you please email me or paste here your running code of email sending .
Your help will be highly appreciable!
ahsan
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
He said that he solved it using JavaMail.
Here is its homepage: http://java.sun.com/products/javamail
Especially checkout the FAQ, it contains lot of information and code examples.
 
firstName SecondName
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bauke Scholtz wrote:He said that he solved it using JavaMail.
Here is its homepage: http://java.sun.com/products/javamail
Especially checkout the FAQ, it contains lot of information and code examples.

hi,
how can i use this javamail .
do you have any suggestions.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As said, especially checkout the FAQ, it contains lot of information and code examples. You can find a link to the FAQ in the left navigatio menu.

It is not that hard. Just create a Java class which does the mailing task independently and test it as a Java application using main(). Once you got that work, just import/use that class in your J2ME application.
 
firstName SecondName
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bauke Scholtz wrote:As said, especially checkout the FAQ, it contains lot of information and code examples.

It is not that hard. Just create a Java class which does the mailing task independently and test it as a Java application using main(). Once you got that work, just import/use that class in your J2ME application.

Thanks for that!
I will do that!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic