Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Smtp Server error with JavaMail

51 views
Skip to first unread message

Federico

unread,
Jul 16, 2003, 11:25:08 AM7/16/03
to
Hi all,


I'm trying to utilize the JavaMail package and I've realized a class.
This is the constructor's code:

public sendMail() throws AddressException, MessagingException {

String smtpServer = new String("mail.tin.it");
String userId = new String("USERID");
String password = new String("PASSWORD");

Properties props = new Properties();
props.put("mail.smtp.host", smtpServer);
props.put("mail.smtp.auth","true");
Session session = Session.getDefaultInstance(props, null);
InternetAddress to = new InternetAddress("TO_ADDRESS");
InternetAddress from = new InternetAddress("FROM_ADDRESS");
Message message= new MimeMessage(session);
message.setFrom(from);
message.setRecipient(Message.RecipientType.TO, to);
message.setSubject("Test JavaMail");
message.setContent("Ciao Mondo","text/plain");
Transport transport = null;
transport = session.getTransport("smtp");
transport.connect(smtpServer, userId, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}

I receive this error message:

javax.mail.NoSuchProviderException: No provider for smtp
at javax.mail.Session.getTransport(Session.java:516)
at javax.mail.Transport.send0(Transport.java:155)
at javax.mail.Transport.send(Transport.java:81)
at sendMail.sendMail.<init>(sendMail.java:43)
at sendMail.sendMail.main(sendMail.java:52)


I'm sure that the SMTP string ("mail.tin.it") is right, it's the same
utilized by my email client. I have to insert the smtp server in some
other way?

Thank you
Federico

Joseph Millar

unread,
Jul 16, 2003, 2:18:38 PM7/16/03
to
On Wed, 16 Jul 2003 15:25:08 GMT, Federico <fmes...@tin.it> wrote:
> javax.mail.NoSuchProviderException: No provider for smtp
> at javax.mail.Session.getTransport(Session.java:516)
> at javax.mail.Transport.send0(Transport.java:155)
> at javax.mail.Transport.send(Transport.java:81)
> at sendMail.sendMail.<init>(sendMail.java:43)
> at sendMail.sendMail.main(sendMail.java:52)

You have smtp.jar in your classpath?

--Joe

GaryM

unread,
Jul 16, 2003, 4:42:34 PM7/16/03
to
Federico <fmes...@tin.it> wrote in
news:tjrahv03gddd2rlmp...@4ax.com:

> Hi all,
>
>
> I'm trying to utilize the JavaMail package and I've realized a class.
> This is the constructor's code:


I am not sure why you are getting the exception. You have got it pretty
much right; however, I am doubtful of the way you are obtaining the
transport. Try the following code changes, which use the destination
address to automatically select the appropriate provider. If it still
does not work then it points to a classpath issue, however if mail.jar
is in the path, I don't see how it could be ...


>
> public sendMail() throws AddressException, MessagingException {
>
> String smtpServer = new String("mail.tin.it");
> String userId = new String("USERID");
> String password = new String("PASSWORD");
>
> Properties props = new Properties();
> props.put("mail.smtp.host", smtpServer);
> props.put("mail.smtp.auth","true");
> Session session = Session.getDefaultInstance(props, null);
>

// InternetAddress to = new InternetAddress("TO_ADDRESS");


Address to = new InternetAddress("TO_ADDRESS");

> InternetAddress from = new InternetAddress("FROM_ADDRESS");
> Message message= new MimeMessage(session);
> message.setFrom(from);
> message.setRecipient(Message.RecipientType.TO, to);
> message.setSubject("Test JavaMail");
> message.setContent("Ciao Mondo","text/plain");

// just for completeness you should do this
message.saveChanges();

> Transport transport = null;
// transport = session.getTransport("smtp");
transport = session.getTransport(to);

> transport.connect(smtpServer, userId, password);
> transport.sendMessage(message, message.getAllRecipients());
> transport.close();
>}

<snip>

Regards,

Gary

Federico

unread,
Jul 16, 2003, 8:15:30 PM7/16/03
to

Thank to both Joseph and Gary, but it's still not working.

The smtp.jar is in the classpath, as the mail.jar and even the
activation.jar.

I've tried with the Gary's suggestions in the code, but it's still not
working.

What could be!??!?!?!?

Now is even changed the errore message:

DEBUG: getProvider() returning
javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
Microsystems, Inc]
java.lang.reflect.InvocationTargetException
at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at
java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at javax.mail.Session.getService(Session.java:607)
at javax.mail.Session.getTransport(Session.java:541)
at javax.mail.Session.getTransport(Session.java:484)
at javax.mail.Session.getTransport(Session.java:464)


at sendMail.sendMail.<init>(sendMail.java:43)

at sendMail.simpleSendMessage.main(simpleSendMessage.java:50)
Caused by: java.lang.NoSuchMethodError:
javax.mail.Session.getDebugOut()Ljava/io/PrintStream;
at
com.sun.mail.smtp.SMTPTransport.<init>(SMTPTransport.java:72)
... 10 more
javax.mail.NoSuchProviderException: smtp
at javax.mail.Session.getService(Session.java:611)
at javax.mail.Session.getTransport(Session.java:541)
at javax.mail.Session.getTransport(Session.java:484)
at javax.mail.Session.getTransport(Session.java:464)


at sendMail.sendMail.<init>(sendMail.java:43)

at sendMail.simpleSendMessage.main(simpleSendMessage.java:50)
Exception in thread "main"

Sudsy

unread,
Jul 16, 2003, 6:17:45 PM7/16/03
to
Federico wrote:
> Hi all,
<snip>

> transport = session.getTransport("smtp");
<snip>

Why are you doing this? I just use:

transport = session.getTransport();

Javadocs say this:

getTransport()
Get a Transport object that implements this user's desired Transport
protcol.

I've never had to give it an argument.

GaryM

unread,
Jul 16, 2003, 10:45:29 PM7/16/03
to
Federico <fmes...@tin.it> wrote in
news:9kqbhv8vsccacf3tu...@4ax.com:

> Thank to both Joseph and Gary, but it's still not working.
>
> The smtp.jar is in the classpath, as the mail.jar and even the
> activation.jar.
>
> I've tried with the Gary's suggestions in the code, but it's still
> not working.
>
> What could be!??!?!?!?

Although you get a javax.mail.NoSuchProviderException I think this is a
red herring as the first line is clearly from the
javamail.default.providers file in mail.jar. If you have this then you
have the SMTPTransport class (it is also invoked in the trace too). So
I no longer think it is a classpath issue.

I am beginning to suspect the SMTP AUTH. I cannot test this myself
easily, but I wonder if you can test it with a non-auth server using
the static method Transport.send(msg)?

GaryM

unread,
Jul 17, 2003, 7:32:29 AM7/17/03
to
GaryM <gar...@yahoo.com> wrote in
news:Xns93BAE78B6C1C1R3...@216.168.3.44:

> Although you get a javax.mail.NoSuchProviderException I think this
> is a red herring as the first line is clearly from the
> javamail.default.providers file in mail.jar. If you have this then
> you have the SMTPTransport class (it is also invoked in the trace
> too). So I no longer think it is a classpath issue.
>
> I am beginning to suspect the SMTP AUTH. I cannot test this myself
> easily, but I wonder if you can test it with a non-auth server
> using the static method Transport.send(msg)?

Sorry to followup on my own post. I just did do a test with your code
on my SMTP AUTH enabled server and it does work.

You seem to be falling over when the Javamail determines the name of
the Transport provider from the javamail.default.providers and
reflection tries to instantiate that class. Therefore:

1. Can you check that you have the com.* hierarchy in your mail.jar and
the integrity of the jar is good?

2. Earlier you referred to "smtp.jar". Can you remove this (it is part
of mail.jar anyway)?

3. I'd still like to see if it works on a non AUTH server.


Here is my debug log:

DEBUG: JavaMail version 1.3
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\j2re1.4.1_
01\lib\javamail.providers (The system cannot find the file specified)
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.providers
DEBUG: successfully loaded resource: /META-
INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name:
{com.sun.mail.smtp.SMTPTransport=javax.mail.Provider
[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc],
com.sun.mail.imap.IMAPStore=javax.mail.Provider
[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc],
com.sun.mail.pop3.POP3Store=javax.mail.Provider
[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]}
DEBUG: Providers Listed By Protocol: {imap=javax.mail.Provider
[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], pop3
=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun
Microsystems, Inc], smtp=javax.mail.Provider
[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]}
DEBUG: successfully loaded resource: /META-
INF/javamail.default.address.map
DEBUG: !anyLoaded
DEBUG: not loading resource: /META-INF/javamail.address.map
DEBUG: java.io.FileNotFoundException: C:\Program Files\Java\j2re1.4.1_
01\lib\javamail.address.map (The system cannot find the file specified)


DEBUG: getProvider() returning javax.mail.Provider
[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]

DEBUG SMTP: useEhlo true, useAuth true
DEBUG: SMTPTransport trying to connect to host "xxxx", port 25

<SNIP>

Federico

unread,
Jul 17, 2003, 11:32:46 AM7/17/03
to
I've checked everything (apart the integrity of the jar, how can you
check it?) and it's still not working. Perhaps it's the system.

Tomorrow I'll try on another system to see what happens

Anyway thanks for everything.

Fede

Federico

unread,
Jul 17, 2003, 11:33:51 AM7/17/03
to
On Wed, 16 Jul 2003 18:17:45 -0400, Sudsy <bitbu...@hotmail.com>
wrote:

>Why are you doing this? I just use:
>
>transport = session.getTransport();
>
>Javadocs say this:
>
>getTransport()
>Get a Transport object that implements this user's desired Transport
>protcol.
>
>I've never had to give it an argument.


In this way I get the following error:

javax.mail.NoSuchProviderException: Invalid protocol: null
at javax.mail.Session.getProvider(Session.java:265)
at javax.mail.Session.getTransport(Session.java:483)
at javax.mail.Session.getTransport(Session.java:464)
at javax.mail.Session.getTransport(Session.java:450)


at sendMail.sendMail.<init>(sendMail.java:43)
at sendMail.sendMail.main(sendMail.java:52)

Exception in thread "main"

Gary M

unread,
Jul 17, 2003, 11:50:14 AM7/17/03
to
Federico <fmes...@tin.it> wrote in
news:7cgdhv43mcl7mfkdp...@4ax.com:

>
> I've checked everything (apart the integrity of the jar, how can you
> check it?) and it's still not working. Perhaps it's the system.
>
> Tomorrow I'll try on another system to see what happens
>
> Anyway thanks for everything.

I use winrar to browse the jar and it also can check the integrity.
Please post back when you solve the problem. Sorry I can't help more.

Gary

Federico

unread,
Jul 17, 2003, 3:20:11 PM7/17/03
to
That's just what I've done.

I hope to have better news tomorrow.

Bye
Fede

On Thu, 17 Jul 2003 15:50:14 -0000, Gary M <gax...@yahoo.com(xx=ry)>
wrote:

Roedy Green

unread,
Jul 17, 2003, 4:59:32 PM7/17/03
to
On Thu, 17 Jul 2003 19:20:11 GMT, Federico <fmes...@tin.it> wrote or
quoted :

>That's just what I've done.
>
>I hope to have better news tomorrow.

I have written a remailer than uses Java mail. You send it an email
and it broadcast it to the attached list of people.

See http://mindprod.com/products.html#BULK

It comes with commented Java source which may help you in your
project.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Federico

unread,
Jul 18, 2003, 4:17:52 PM7/18/03
to
I've wrote the same code on another machine and it works perfectly

Really don't know what's happening on the machine where isn't working,
but I'm happy it works where I have to implement the application :-)

Thank you for all of your suggestion.

Fede

Scott Yanoff

unread,
Jul 21, 2003, 10:54:54 AM7/21/03
to
Federico wrote:

> I've wrote the same code on another machine and it works perfectly
>
> Really don't know what's happening on the machine where isn't working,
> but I'm happy it works where I have to implement the application :-)

I do not know the ins and outs of JavaMail, but does the machine where
this did not work on have access to the mail server you are using? Try
pinging the mail server hostname from that machine. I believe that
JavaMail connects to port 25 of the server, so perhaps you could try:

telnet machineName 25
EHLO

You should get some type of greeting message back after typing EHLO.

Cheers,


--
-Scott
yan...@STOP-SPAMMINGyahoo.com | http://www.yanoff.org | AOL IM: SAY KJY

0 new messages