Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java API
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Ron McLeod
Jeanne Boyarsky
Paul Clapham
Sheriffs:
Liutauras Vilda
Henry Wong
Devaka Cooray
Saloon Keepers:
Tim Moores
Stephan van Hulst
Tim Holloway
Al Hobbs
Carey Brown
Bartenders:
Piet Souris
Mikalai Zaikin
Himai Minh
Forum:
Other JSE/JEE APIs
Problem in Javamail
yogi maheshnath
Ranch Hand
Posts: 30
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
JSP
code
<jsp:useBean id="mailer" class="com.email.SendMail"> <% String from=request.getParameter("email1"); String subject=request.getParameter("subject"); String name=request.getParameter("name"); String coname=request.getParameter("coname"); String message=request.getParameter("message"); String[] emailList = {"xyz@yahoo.co.in"}; mailer.postMail(emailList,subject,message,from); %> </jsp:useBean>
-----------------
Java
Bean Code
package com.email; import javax.mail.*; import javax.mail.internet.*; import java.util.*; import java.io.*; import javax.mail.Authenticator; public class SendMail { /*private static final String SMTP_HOST_NAME = "my hostname"; private static final String SMTP_AUTH_USER = "my username"; private static final String SMTP_AUTH_PWD = "my password"; private static final String emailMsgTxt = "Online Order Confirmation Message. Also include the Tracking Number."; private static final String emailSubjectTxt = "Order Confirmation Subject"; private static final String emailFromAddress = "sudhir@java.com"; // Add List of Email address to who email needs to be sent to private static final String[] emailList = {"xyz@yahoo.co.in"};*/ public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException { boolean debug = false; //Set the host smtp address Properties props = new Properties(); props.put("mail.smtp.host", "my hostname"); props.put("mail.smtp.auth", "true"); Authenticator auth = new SMTPAuthenticator(); Session session = Session.getDefaultInstance(props, auth); session.setDebug(debug); // create a message Message msg = new MimeMessage(session); // set the from and to address InternetAddress addressFrom = new InternetAddress(from); msg.setFrom(addressFrom); InternetAddress[] addressTo = new InternetAddress[recipients.length]; for (int i = 0; i < recipients.length; i++) { addressTo[i] = new InternetAddress(recipients[i]); } msg.setRecipients(Message.RecipientType.TO, addressTo); // Setting the Subject and Content Type msg.setSubject(subject); msg.setContent(message, "text/plain"); Transport.send(msg); } /** * SimpleAuthenticator is used to do simple authentication * when the SMTP server requires it. */ private class SMTPAuthenticator extends javax.mail.Authenticator { public PasswordAuthentication getPasswordAuthentication() { String username = "my username"; String password = "my password"; return new PasswordAuthentication(username, password); } } }
-------------------------------------
when i use jsp code,following exception occurs,Please Explain
type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: javax/mail/Authenticator org.apache.jasper.servlet.JspServlet.service(JspServlet.java:244) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) root cause java.lang.NoClassDefFoundError: javax/mail/Authenticator java.lang.Class.getDeclaredConstructors0(Native Method) java.lang.Class.privateGetDeclaredConstructors(Class.java:1618) java.lang.Class.getConstructor0(Class.java:1930) java.lang.Class.getConstructor(Class.java:1027) org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1222) org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116) org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163) org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213) org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219) org.apache.jasper.compiler.Node$Root.accept(Node.java:456) org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163) org.apache.jasper.compiler.Generator.generate(Generator.java:3272) org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:244) org.apache.jasper.compiler.Compiler.compile(Compiler.java:470) org.apache.jasper.compiler.Compiler.compile(Compiler.java:451) org.apache.jasper.compiler.Compiler.compile(Compiler.java:439) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Thanks&Regards<br />Yogi MaheshNath
Sivaraman Lakshmanan
Ranch Hand
Posts: 231
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
Add mail.jar to your classpath and then give a try.
Regards,
Sivaraman.L
Stony Zhang
Greenhorn
Posts: 2
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You should
add JAF to your classpath.
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Mail
urgent help in java mail
Getting exception in sending Email from Servlet
Need Information about sending email Please
javamail.providers
More...