Re: Issues with GWT deployed to Tomcat (not AppEngine) and using javax.mail server-side
Hey
First, as long as the code is not compiled by GWT, GWT has zero effect on it. So your problem is likely not GWT related.
It's difficult to tell from your error 'The API package 'mail' or call 'Send()' was not found.' - I've never seen a java error like this one before.
Do you maybe have the mail code inside the package you have specified gwt to build in your gwt.xml file ? If so, you need to move it to a different package. eg, com.name.client for gwt code and com.name.server for server/mail code.
On Saturday, July 6, 2013 8:37:46 PM UTC+2, judd gilbert wrote:
Hello,
I'm having an issue using javax.mail server side (deployed on my own server, not AppEngine). I wrote the following mail class:
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class CMail {
final String username = "my...@myserver.com";
final String password = "password";
Properties props = new Properties();
String mailhost="mail.myserver.com";
String from = "my...@myserver.com";
StringBuilder to = null;
int port = 25;
String subject = null;
StringBuilder text = new StringBuilder();
public CMail(String subject) {
this.subject = subject;
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "mail.myserver.com");
props.put("mail.smtp.port", "587");
}
public void addRecipient(String recipient) {
if (to == null) {
to = new StringBuilder();
}
if (to.length() > 0)
to.append(", " + recipient);
else
to.append(recipient);
}
public void addText(String text) {
this.text.append(text);
}
public void send() {
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO , InternetAddress.parse(to.toString()));
message.setSubject(subject);
message.setText(this.text.toString());
Transport.send(message);
}
catch (MessagingException e) {
e.printStackTrace();
}
}
}
And on my server-side code I call it like so:
public class MyServiceImpl extends RemoteServiceServlet implements
myService {
/** most stuff (RPC calls, members, constructor) left out for readability ***/
public Boolean sendEmail() {
try {
CMail mail = new CMail("Test Mail");
mail.addRecipient("m...@myserver.com ");
mail.addText("This is a test email.\n");
mail.send();
return true;
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
}
Now, if I create a java application (non-GWT) this code executes perfectly and I get email. In my GWT app it throws an exception when it gets to the "Transport.send(msg)" line. This is the error:
The API package 'mail' or call 'Send()' was not found.
Now remember this is server side code. The javax.mail.jar is in my WEB-INF/libs directory. It doesn't work locally (in dev mode, which I wouldn't expect it to) or when I deploy it to my server. I am using standard RPC deployment style, just copying my WAR directory over. I added the msql stuff in the same manner and it gives me no issues either deployed or undeployed.
I can't really remove the GWT jars (of which there are 4) without the whole project breaking down. I've tried adding javax.activation and that didn't help. Now I'm stuck for 2 days so far.
Does anyone have any suggestions? I'm really desperate, because I built all this code working up to this point, and I'll have to throw most of it away if I can't get email and GWT to play nice.
Thanks,
Judd
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home