I am having a bit of an issue testing my web application. I have written a customized Emailer class that is used to send an email to the specified email address. I am able to get the class to successfully send an email while using a driver class, however, when I attempt to use the Emailer class on the server side, no email is sent. I have embeded the code in a try-catch block and I am not catching any exceptions. Does anyone have any knowledge as to why this may be the case?
Server Side Code:
************************************************************************************************************************
/**
* The server side implementation of the RPC service.
*/
@SuppressWarnings("serial")
public class EmailServiceImpl extends RemoteServiceServlet implements EmailService {
public String sendEmail(String email) {
try {
Emailer eMail = new Emailer();
eMail.setEmailRecipient(email);
eMail.setEmailSender(email);
eMail.setEmailSubject("Its Jail!");
eMail.setEmailText("No, java mail silly!!...");
eMail.send();
return "an email has successfully been sent to the specified email address.";
} catch(Exception e) {
return "An exception has occured.";
}
}
}
************************************************************************************************************************
Emailer class:
************************************************************************************************************************
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class Emailer {
private String smtpHost;
private int smtpPort;
private String emailSender;
private String emailRecipient;
private String emailSubject;
private String emailText;
public Emailer() {
smtpHost = "
mysmtphost";
smtpPort = 25;
}
public Emailer(String host, int port) {
smtpHost = host;
smtpPort = port;
}
public void setEmailSender(String sender) {
emailSender = sender;
}
public void setEmailRecipient(String recipient) {
emailRecipient = recipient;
}
public void setEmailSubject(String subject) {
emailSubject = subject;
}
public void setEmailText(String text) {
emailText = text;
}
public void send() {
Properties props = new Properties();
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.port", smtpPort);
Session ses = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(ses);
try {
msg.setFrom(new InternetAddress(emailSender));
msg.setRecipient(
Message.RecipientType.TO, new InternetAddress(emailRecipient));
msg.setSubject(emailSubject);
msg.setText(emailText);
Transport.send(msg);
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
************************************************************************************************************************