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
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();
}
}
}
 
 
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