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 = "[email protected]";
final String password = "password";
Properties props = new Properties();
String mailhost="mail.myserver.com";
String from = "[email protected]";
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("[email protected]");
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.