开发者

Sending email with GWT: getting AccessControlException

I have this issue that I cant seem to solve easily.

I want to send an email from within a GWT webApp. I d开发者_StackOverflowid everything correctly in terms of putting the code in the server side and invoking it with an Async interface as its expected. So all is ok, except that when I execute the send email function, I get an error of type mailexception with and inner exception of type AccessControlException "access denied (java.net.SocketPermission <my smtp server> resolve)".

Now I tested the function in a regular Java console app and it worked perfectly. So I guess I need to add some code to grant access somehow. Anyone can assist me in this?

Here is the code of the send email:

    public void SendMail(String name, String email, String message) throws EmailException{
    Email email1 = new SimpleEmail();
    email1.setHostName("mysmtpserver");
    email1.setSmtpPort(25);
    email1.setAuthenticator(new DefaultAuthenticator("myemail", "mypwd"));
    email1.setTLS(false);
    email1.setFrom(email);
    email1.setSubject("Feedback from your website");
    email1.setMsg(escapeHtml(message));
    email1.addTo("targetemail");
    email1.send();
}

and that's the code of the class calling it:

public class SiteDataServiceImpl extends RemoteServiceServlet implements SiteDataService {
@Override
public boolean SendEmail(String name, String email, String message) throws IllegalArgumentException {
    try {
        new Common().SendMail(name, email, message);
        return true;
    } catch (EmailException e) {
        e.printStackTrace();
        return false;
    }
}

}

PS: I thought at first that I need to include the mail.jar archive, but it is included in the gwt toolkit already, so its not the cause of the problem. And I am using Jetty with Eclipse.


Ok this may sound weird, but I deployed the code on a dev server (linux) and it worked like a charm.

On my machine a windows one, it is still not working, and still getting the same error. But since it works on the dev machine, I am happy.

However this still doesnt explain the reason....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜