Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

to send an email from a servlet  RSS feed

Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!