Here is a sample code segment ( which is working ) for sending mail
using Google App Engine. Please see the documentation @ "http://
download.oracle.com/javaee/1.4/api/index.html". Hope it helps.
S. Abraham
www.DataStoreGwt.com
// client side code
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
public class MainEntry implements EntryPoint {
RequestBuilder rb = null;
@Override
public void onModuleLoad() {
// Window.Location.replace("/hello");
rb = new RequestBuilder(RequestBuilder.POST, "mailserver");
rb.setCallback(new RequestCallback() {
@Override
public void onResponseReceived(Request request,
Response response)
{
// TODO Auto-generated method stub
Window.alert("Mail send");
}
@Override
public void onError(Request request, Throwable
exception) {
// TODO Auto-generated method stub
}
});
Button button = new Button("Mail service");
button.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// TODO Auto-generated method stub
try {
rb.send();
} catch (RequestException e) {
}
}
});
RootPanel.get().add(button);
}
}
// server side code
import java.io.UnsupportedEncodingException;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MailServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doPost(HttpServletRequest req, HttpServletResponse resp)
{
System.out.println("Mail Servlet is called");
Properties properties = new Properties();
Session session = Session.getDefaultInstance(properties, null);
String message = "Welcome to www.datastoregwt.com";
try
{
Message msg = new MimeMessage(session);
msg.setFrom(new
InternetAddress("[email protected]"));
msg.addRecipient(Message.RecipientType.TO, new
InternetAddress("[email protected]"));
msg.setSubject("Invitation from www.tanya.com");
msg.setText(message);
Transport.send(msg);
}
catch (AddressException e1)
{
}
catch (MessagingException e2)
{
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
}
}
On Sep 13, 3:05 pm, James Briant <[email protected]> wrote:
> My app can't send email any more. I get this exception every time:
>
> com.google.apphosting.api.ApiProxy$ApiDeadlineExceededException: The API
> call mail.Send() took too long to respond and was cancelled
>
> Here's the time for the incoming call: ms=6640 cpu_ms=1568 api_cpu_ms=658
> cpm_usd=0.069988
>
> What's going on and what do I do about it?
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.