aspose file tools*
The moose likes Servlets and the fly likes email sending code is not working in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "email sending code is not working in servlet" Watch "email sending code is not working in servlet" New topic
Author

email sending code is not working in servlet

waqas imtiaz
Ranch Hand

Joined: Mar 20, 2014
Posts: 45
Roger Sterling
Ranch Hand

Joined: Apr 06, 2012
Posts: 426

- Please edit your post to use [c ode] tags.
- Don't use gmail / google as your outbound mail server.
- Setup your own mailserver for outbound processing or use your University's mailserver or rent a $1.99 Web account from 1&1.com and use it's mail service.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41843
    
  63
Note that you should never use GET and POST interchangeably, no matter how many servlet tutorials erroneously show that.

You should turn on JavaMail debugging so that you get a lot more output about what's (not) happening: http://www.oracle.com/technetwork/java/faq-135477.html#debug


Ping & DNS - my free Android networking tools app
waqas imtiaz
Ranch Hand

Joined: Mar 20, 2014
Posts: 45
Why not using Google or Gmail?
Though this code worked for many times in this servlet. But is not working now. I do not know what is wrong with this code
Roger Sterling
Ranch Hand

Joined: Apr 06, 2012
Posts: 426

Because you don't own those resources and up-time or serviceability is not guaranteed. Also because running your own mailserver is easy to do and free-of-charge, giving you control over how your mail gets handled. If you don't want to learn to do that, rent a Web space from 1&1.com for $1.99 per month and you get ten free mail accounts on that domain.

Using Gmail/Google is a bad idea because you do not have control over when your mail gets delivered or when the service changes or who has access to the content of your mail to include the email Id of the person you are sending to.
waqas imtiaz
Ranch Hand

Joined: Mar 20, 2014
Posts: 45
Well actually it make no difference to me as it is my university project only. And long as when server is on or not is concerned, it always sends an email when used from command line. But creates problems when sent from servlet
Roger Sterling
Ranch Hand

Joined: Apr 06, 2012
Posts: 426

There may be nothing wrong with your code, but the Gmail SMTP port may be rejecting your mail. Google limits the number of messages you can send per hour. If you are over-limit, your code works, but Gmail doesn't.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41843
    
  63
waqas imtiaz wrote:I do not know what is wrong with this code

That is why I suggested using the dedug option; have you done that yet? If not, start with that. Don't get distracted by a discussion of Gmail vs. not Gmail. That may or may not be the problem, but if the mail code has worked for you before, chances are it's not. But using the debug option is highly likely to help you in debugging.
waqas imtiaz
Ranch Hand

Joined: Mar 20, 2014
Posts: 45
With debug statement I tried couple of times and it worked both the times. What is magic related to this Debug statement?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41843
    
  63
The point of the debug option is that it produces LOTS of output that tells you what's going on, particularly if something goes wrong. Did you see that output in the log files?
waqas imtiaz
Ranch Hand

Joined: Mar 20, 2014
Posts: 45
I worked again with this session.setDebug(true);
Why did it run please explain???
waqas imtiaz
Ranch Hand

Joined: Mar 20, 2014
Posts: 45
Ulf Dittmer wrote:The point of the debug option is that it produces LOTS of output that tells you what's going on, particularly if something goes wrong. Did you see that output in the log files?


I actually saw all of those outputs. But nothing is wrong and program worked every time with debug statement. Why is so?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41843
    
  63
You shouldn't be surprised that your code works Of course, we can't speculate why it's not failing now, because we have no idea why it was failing before. So I guess the lesson is to keep the debug option turned on, so that if things fail again, you'll have the debug output to look into.
waqas imtiaz
Ranch Hand

Joined: Mar 20, 2014
Posts: 45
Ulf Dittmer wrote:You shouldn't be surprised that your code works Of course, we can't speculate why it's not failing now, because we have no idea why it was failing before. So I guess the lesson is to keep the debug option turned on, so that if things fail again, you'll have the debug output to look into.


Yeh you are right. Thank you all of the guys for helping.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: email sending code is not working in servlet