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
Win a copy of
OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830
this week in the
Programmer Certification
forum!
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
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Other JSE/JEE APIs
JavaMail, servlet error
malik ge
Ranch Hand
Posts: 69
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi, I have tried to send mail through a
java
file. It worked fine.
but, when I try to copy the same code to my
servlet
it gave errors, from line 29 to 36 that "@Override method does not override or implement a method from a super-type"
any help...
Servlet code:
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.*; import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class EmailServlet extends HttpServlet { public void sendEmail() { try { Properties props = new Properties(); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.socketFactory.port", "465"); props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.port", "465"); Session session = Session.getDefaultInstance(props,new javax.mail.Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("gmailUserName","password"); } } ); Message message = new MimeMessage(session); message.setFrom(new InternetAddress("gmailID@gmail.com")); message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("someAddress@gmail.com")); message.setSubject("Testing Subject"); message.setText("Hello, this is a message...!"); Transport.send(message); System.out.println("Message sent"); } catch (Exception e) { System.out.println("Failed to send email: " + e); } } @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { sendEmail(); response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("Email sent"); } }
Ulf Dittmer
Rancher
Posts: 43081
77
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Both JSE and
JEE
each have a class called
PasswordAuthentication
- you're importing the wrong one.
malik ge
Ranch Hand
Posts: 69
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks a lot man...
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to configure localhost to send email.
Getting javax.mail.SendFailedException: Sending failed; Please Help its Urgent
java mail
SHA1 digest error for javax/mail/MessagingException
How to send mail form java application
More...