File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes NoSuchProviderException: smtp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "NoSuchProviderException: smtp" Watch "NoSuchProviderException: smtp" New topic
Author

NoSuchProviderException: smtp

Raja Islam
Ranch Hand

Joined: Dec 07, 2001
Posts: 74
Hi
i am using outlook to send mail it is working fine but when i am using java code it produce follwing error
************************************************************
Exception in thread "main" javax.mail.NoSuchProviderException: smtp
at javax.mail.Session.getService(Session.java:746)
at javax.mail.Session.getTransport(Session.java:685)
at javax.mail.Session.getTransport(Session.java:628)
at javax.mail.Session.getTransport(Session.java:608)
at javax.mail.Session.getTransport(Session.java:663)
at javax.mail.Transport.send0(Transport.java:154)
at javax.mail.Transport.send(Transport.java:80)
at M.main(M.java:15)
************************************************************
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class myOutlook {
public static void main(String[] args)throws MessagingException {
Properties prop=System.getProperties();
prop.put("mail.smtp.host","mail.wtmeca.net");
Session sess=Session.getInstance(prop,null);
MimeMessage msg=new MimeMessage(sess);
msg.setFrom(new InternetAddress("rajami2@yahoo.com"));
msg.setRecipient(Message.RecipientType.TO,new InternetAddress("rajami2@hotmail.com"));
msg.setSubject("786");
msg.setText("Ya Allah");
Transport.send(msg);
}
}
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

You need to build your Transport object


/Rene
[ July 21, 2002: Message edited by: Rene Larsen ]

Regards, Rene Larsen
Dropbox Invite
Raja Islam
Ranch Hand

Joined: Dec 07, 2001
Posts: 74
Hi
it produce follwing error
*************************************************
Exception in thread "main" javax.mail.NoSuchProviderException: No provider for m
ail.wtmeca.net
at javax.mail.Session.getProvider(Session.java:433)
at javax.mail.Session.getTransport(Session.java:627)
at javax.mail.Session.getTransport(Session.java:608)
at M.main(M.java:17)
************************************************
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class M {
public static void main(String[] args)throws MessagingException {
Properties prop=System.getProperties();
prop.put("mail.smtp.host","mail.wtmeca.net");
Session sess=Session.getInstance(prop,null);
MimeMessage msg=new MimeMessage(sess);
msg.setFrom(new InternetAddress("rajami2@yahoo.com"));
msg.setRecipient(Message.RecipientType.TO,new InternetAddress("rajami2@hotmail.com"));
msg.setSubject("786");
msg.setText("Ya Allah");
Transport transport = sess.getTransport("mail.wtmeca.net");
transport.connect("mail.wtmeca.net", "username", "password");
transport.send(msg);
}
}
can u tell me what the real prob was with my code because i cut paste this from Book.and not a single line is added from myself it is all from book.
Thankx
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179


should be:

/Rene
Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
Try to use Sun's made package for smtp transportation.
Here is a piece of code, it might help:
import sun.net.smtp.SmtpClient;
import java.io.*;
....bla bla bla.....
public void sendItBaby()
{
String from="spammer@java.com";
String to="winfan@ms.com";
try{
SmtpClient client = new SmtpClient("smtp.server.com");
client.from(from);
client.to(to);
PrintStream message = client.startMessage();
message.println("To: " + to);
message.println("Subject: I love you!");
message.println("Java rules! ");
message.println();
message.println("MS doesn't!");
message.println();
message.println("End of message.");
client.closeServer();
out.println("EMail has been sent.");
}
catch (IOException e){
out.println("ERROR SENDING EMAIL:"+e);
}
...bla bla bla...
enjoy!


Asher Tarnopolski
SCJP,SCWCD
Raja Islam
Ranch Hand

Joined: Dec 07, 2001
Posts: 74
Hi
thankx for reply but can u tell me what the prob with my code??
Raja Islam
Ranch Hand

Joined: Dec 07, 2001
Posts: 74
Hi
The prob was that i did not included smtp.jar and i am thinkig that all the required classes are in mailapi.jar and activation.jar now it is working fine but it is slow in sending mail as compare to servlet .
Thankx
Patrick Shea
Greenhorn

Joined: May 09, 2011
Posts: 2
Thanks for the tip. I was having the same issue and also forgot to include smtp.jar
chandrashekhara siddalingappa
Greenhorn

Joined: Aug 07, 2012
Posts: 2
<%@page import="com.sun.mail.smtp.SMTPTransport"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.*" %>
<%@page import="javax.mail.*" %>
<%@page import="javax.mail.internet.*" %>
<%@page import="javax.mail.*,javax.mail.event.*,javax.mail.internet.*" %>
<%@page import="javax.servlet.http.*" %>
<%@page import="javax.servlet.*" %>
<%@page language="java"%>

<%@page import="javax.naming.*" %>

<%
String result="";
String pass="";
String to=request.getParameter("email");

String from="chandrais010@gmail.com";

Properties props = System.getProperties();
props.put("mail.smtp.host", "smtp.mail.gmail.com");
Session mailSession = Session.getDefaultInstance(props);
try{
MimeMessage message = new MimeMessage(mailSession);
message.setSubject("forget password");
InternetAddress ifrom=new InternetAddress(from);
message.setFrom(ifrom);
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/result","root","root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select password from vendorslogin where email='"+to+"'");

if(rs.next()){
pass=rs.getString("password");
}
else{
out.println("Invalid");
}
//Store store=mailSession.getStore("pop3");
//store.connect("pop.gmail.com",25,null,null);

message.setText(pass);

Transport transport=mailSession.getTransport("smtp");
transport.connect("smtp.mail.gmail.com", "chandrais010@gmail.com","8971903885" );
Transport.send(message);
transport.close();
result = "Sent message successfully....";

rs.close();
st.close();
con.close();
}
catch (MessagingException mex) {
mex.printStackTrace();
result = "Error: unable to send message....";
}
catch(Exception e){}
%>
<html>
<head>
<title>Send Email using JSP</title>
</head>
<body>
<center>
<h1>Send Email using JSP</h1>
</center>
<p align="center">
<%
out.println("Result: " + result + "\n");
%>
</p>
</body>
</html>

sir, here it is showing error

javax.mail.MessagingException: Could not connect to SMTP host: smtp.mail.gmail.com, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1972)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:642)
at javax.mail.Service.connect(Service.java:295)
at javax.mail.Service.connect(Service.java:176)
at org.apache.jsp.recoverpass_jsp._jspService(recoverpass_jsp.java:109)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:337)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:198)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:180)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:319)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:233)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1938)
... 22 more

i want to send password to user through emaikl
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NoSuchProviderException: smtp