Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Problem with mail api on google app engine.

 
Ranch Hand
Posts: 607
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I trying to send mails using the google app engine, but am facing a problem.

Here is my code



and my struts config mapping is



The error I get is,

Error: Server Error

The server encountered an error and could not complete your request.
If the problem persists, please report your problem and mention this error message and the query that caused it.


Any help here?
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which line triggers the problem? Is there a stack trace? Does one of the exceptions happen that the code is currently ignoring?
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The truth is I have no idea. I cant run the code locally, since the mail API requires that I run the code on the google server (at least thats what I think right now).

When I run it on the server there is really no place where I can see the stack trace. At least none that I know off. So I am stuck right now - not sure of something is wrong with my code or just something wrong with the way I am trying to deploy it.

I was just wondering if there is someone who already has an app deployed on google app (Java) and is using the mail service - could probably help me out.

I realized that it better posting this question at the Google app forums (I sure there would be some) but JR is my favorite place - so its out of habit that I posted here

P.S -- I have not cross posted this question anywhere. So I am still looking out for an answer. If I do cross post- I mention so clearly at both places. Dont want the Bartenders locking up my post do I
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't GAE have a logging API you can use to pinpoint the line where the problem occurs?
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may be off base, but I have never tried to use the Transport's methods directly - I have always used a concrete instance of a Transport. This way I can specify what sort of a server I am connecting to, and what my credentials are when connecting.

For example, sending an email from my local computer through GMail, I use:

Note that I am specifying that I am going to use SMTP using the secure port (you are not specifying what protocol you are using), and I am explicitly naming the SMTP server I am connecting to, and what my username and password are (you are not specifying any of this).

I don't know if this is any different when using the google app engine. I wouldn't have thought it would be any different though.
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Ulf - I don't think google provides any logging API.
I could use log4j. Even if I did I wonder where my log file would end up since I don't have access to the server drives. Nor do I think there is any concept of console.

@Andrew - Actually it is a bit different. This is what the API document says,

Sending Mail with the JavaMail API
The Mail service Java API supports the JavaMail (javax.mail) interface for sending email messages.
When creating a JavaMail Session, you do not need to provide any SMTP server configuration. App Engine will always use the Mail service for sending messages.



I should have probably mentioned this before -- http://code.google.com/appengine/docs/java/mail/overview.html
It's a pretty short documentation explaining how to send mail using google app server. My code is just a copy paste from out there ...

I just read the documentation a bit more carefully and it says I should be able to run the mail locally - since I am getting an exception while doing so I think I doing something wrong. I need to look at it again.

P.S - I haven't posted my local exception yet - currently I need to dash somewhere, I'll post the exception as soon as I get back. Probably work a bit on it myself first!

Thanks Ulf and Andrew for helping me out.
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found where the Google app engine logs the errors,

Its in the Dashboard page --> Logs

Here is the error I get,

#

1.
06-13 06:45AM 50.361 /adminMailTest.do 500 1000ms 2110cpu_ms 151api_cpu_ms 0kb 1.latest.mytestapplication-sam.appspot.com Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11,gzip(gfe)
See details

60.243.79.240 - - [13/Jun/2009:06:45:51 -0700] "GET /adminMailTest.do HTTP/1.1" 500 0 - "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11,gzip(gfe)" "1.latest.mytestapplication-sam.appspot.com"

2.
W 06-13 06:45AM 51.350

Error for /adminMailTest.do
java.lang.NoClassDefFoundError: java.net.Socket is a restricted class. Please see the Google App Engine developer's guide for more details.
at com.google.apphosting.runtime.security.shared.stub.java.net.Socket.<clinit>(Socket.java)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:261)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:227)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1511)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:453)
at javax.mail.Service.connect(Service.java:248)
at javax.mail.Service.connect(Service.java:91)
at javax.mail.Service.connect(Service.java:76)
at javax.mail.Transport.send(Transport.java:94)
at javax.mail.Transport.send(Transport.java:48)
at com.twisters.action.admin.MailTest.execute(MailTest.java:36)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:237)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at org.mortbay.jetty.Server.handle(Server.java:313)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:830)
at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:125)
at com.google.apphosting.runtime.JavaRuntime.handleRequest(JavaRuntime.java:235)
at com.google.apphosting.base.RuntimePb$EvaluationRuntime$6.handleBlockingRequest(RuntimePb.java:4755)
at com.google.apphosting.base.RuntimePb$EvaluationRuntime$6.handleBlockingRequest(RuntimePb.java:4753)
at com.google.net.rpc.impl.BlockingApplicationHandler.handleRequest(BlockingApplicationHandler.java:24)
at com.google.net.rpc.impl.RpcUtil.runRpcInApplication(RpcUtil.java:359)
at com.google.net.rpc.impl.Server$2.run(Server.java:800)
at com.google.tracing.LocalTraceSpanRunnable.run(LocalTraceSpanRunnable.java:56)
at com.google.tracing.LocalTraceSpanBuilder.internalContinueSpan(LocalTraceSpanBuilder.java:510)
at com.google.net.rpc.impl.Server.startRpc(Server.java:756)
at com.google.net.rpc.impl.Server.processRequest(Server.java:348)
at com.google.net.rpc.impl.ServerConnection.messageReceived(ServerConnection.java:459)
at com.google.net.rpc.impl.RpcConnection.parseMessages(RpcConnection.java:319)
at com.google.net.rpc.impl.RpcConnection.dataReceived(RpcConnection.java:290)
at com.google.net.async.Connection.handleReadEvent(Connection.java:419)
at com.google.net.async.EventDispatcher.processNetworkEvents(EventDispatcher.java:762)
at com.google.net.async.EventDispatcher.internalLoop(EventDispatcher.java:207)
at com.google.net.async.EventDispatcher.loop(EventDispatcher.java:101)
at com.google.net.rpc.RpcService.runUntilServerShutdown(RpcService.java:251)
at com.google.apphosting.runtime.JavaRuntime$RpcRunnable.run(JavaRuntime.java:373)
at java.lang.Thread.run(Unknown Source)



I have already mentioned what my code is in the original post and all I am doing is following the steps mentioned in the documentation http://code.google.com/appengine/docs/java/mail/overview.html

Any pointers/help would be really great - Right now I really stuck bad at this!
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My problem got solved.
What i was doing wrong was I had included the jar files --> mail.jar, mailapi.jar, smpt.jat and pop3.jar in my project.
However to get the mail to work correctly these jar files are not required and rather I must depend on the implementation provided by google in the app engine jar file.

Just deleting these jar files from my lib directory worked.

http://groups.google.com/group/google-appengine-java/browse_thread/thread/9e771ba1c5d46dad/c22a1e995c433591?lnk=gst&q=sending+mail#c22a1e995c433591
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what jar file did you use for the app engine? i downloaded the app engine sdk but there are so many jar files here i dont know which one to use just for sending mail
 
mark goking
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
by the way, i also read that you have to place this in the google server in order to run? what if i want it to run in my own remote server? not possible?

since i am only interested in google app's gmail service. not the public gmail service
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The jar for the google mail api would only work on the Google App server (atleast that's what I think). If you require to host an application outside the app server you will have to use the traditional mail api...
 
mark goking
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so it just is not possible to use the google app's gmail service since i would have to upload the application/web application to google's server in order for it to be able to use the app engine's mail services, am i correct?
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes that is my understanding too.

P.S If you wish too see how the app-engine mail services works you could try it out by registering at http://treasureHunt.quiz4j.com - It will send you a confirmation mail - Its uses the google app engine to send the mail (The application is deployed on google apps)
 
mark goking
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if it's any cosolation

http://tech.chitgoks.com/2009/08/19/using-smtp-service-in-google-app-engine/

you can still use gmail's smtp server remotely even if your domain is under google apps.
 
Saloon Keeper
Posts: 2662
130
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this mail api is just google app specific ?

so, is this an actual "mail api" ?
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

salvin francis wrote:this mail api is just google app specific ?
so, is this an actual "mail api" ?



No the API is not google specific - only the implementation is - the API is the normal mail api.

Only thing is when trying to access the google app mail server you need to make sure that you include the Mail jar files provided by Google and not those provided by Sun (or whoever provides the mail api implementation jars!)

Though I think Google does make using the API somewhat simpler - you can have look at some sample code here.


 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic