File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "to send an email from a servlet" Watch "to send an email from a servlet" New topic

to send an email from a servlet

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
The javadoc says almost the same thing about the exception.
Somebody please explain what it means and what needs to be changed?
public class MailServlet extends HttpServlet
static final String FROM = "abc";
static final String TO = "";
private String smtpHost = "";
public void init(ServletConfig config) throws ServletException
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
String msgText = "A Body";
boolean debug = true;
Properties properties = new Properties();
properties.put("", smtpHost);
Session session=Session.getDefaultInstanceproperties, null);
Message msg = new MimeMessage(session);
InternetAddress from = new InternetAddress(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.sendMessage(msg, address);
catch (MessagingException mex)
I agree. Here's the link:
subject: to send an email from a servlet
It's not a secret anymore!