wood burning stoves 2.0*
The moose likes Servlets and the fly likes to send an email from a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "to send an email from a servlet" Watch "to send an email from a servlet" New topic
Author

to send an email from a servlet

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I am trying to use the following code to send an email to myself using a servlet and a weblogic server.When I run the program,the error is NoServiceProviderException for xyz@xxx.xxx.com.
The javadoc says almost the same thing about the exception.
Somebody please explain what it means and what needs to be changed?
*******************************************
import.............
public class MailServlet extends HttpServlet
{
static final String FROM = "abc";
static final String TO = "xyz@xxx.xxx.com";
private String smtpHost = "xxx.xxx.com";
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String msgText = "A Body";
boolean debug = true;
Properties properties = new Properties();
properties.put("mail.smtp.host", smtpHost);
Session session=Session.getDefaultInstanceproperties, null);
session.setDebug(debug);
try
{
Message msg = new MimeMessage(session);
InternetAddress from = new InternetAddress(FROM);
msg.setFrom(from);
InternetAddress [] address = {new InternetAddress(TO)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Test Mail");
msg.setContent(msgText, "text/plain");
Transport trans = session.getTransport(TO);
trans.connect();
trans.sendMessage(msg, address);
/**Transport.send(msg);*/
}
catch (MessagingException mex)
{
mex.printStackTrace();
}
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: to send an email from a servlet