my dog learned polymorphism*
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 Android Security Essentials Live Lessons this week in the Android 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)
subject: to send an email from a servlet
Similar Threads
Can i send mail to other than Local Address with this code..i mean to Yahoo or Gmail
Getting exception in sending Email from Servlet
Sending dynamic content by email in jsp
about the exception from the mail servlet
Regarding Mail Server Connect