This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Java Mail problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Java Mail problem " Watch "Java Mail problem " New topic
Author

Java Mail problem

Amin Rais
Greenhorn

Joined: Aug 28, 2002
Posts: 20
Hi,
I create a simple program to send an email :
------------------------------------------------------------
Properties props = new Properties();
// Setup mail server
props.put("mail.smtp.host", hostName);
// Get session
session = Session.getDefaultInstance(props, null);
Provider[] providers = session.getProviders();
System.out.println("Provider List !!");
for (int i = 0; i < providers.length; i++)
System.out.println(providers.getProtocol() + " " +
providers.getClassName() + " " +
providers.getVendor() + " " +
providers.getVersion());
// Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(sender));
for (int i = 0; i < recipents.length; i++)
{
message.addRecipient(Message.RecipientType.TO, new InternetAddress (recipents));
}
message.setSubject(subject);
message.setText(content);
// Send message
Transport.send(message);
------------------------------------------------------------
In that app, some of variables are missing to simplify the codes.
Well the codes running well, and is able to send the email
if I run it under the IDE like JBuilder or any IDE..
But if I put it into JAR file then I can't execute because
of : No providers available..
Thus these lines print nothing ...
for (int i = 0; i < providers.length; i++)
System.out.println(providers.getProtocol() + " " +
providers.getClassName() + " " +
providers.getVendor() + " " +
providers.getVersion());
How can I set the provider ?
Thx...
Pete Lyons
Ranch Hand

Joined: Aug 18, 2002
Posts: 109
I think this is just because you don't have Sun's mail implementation jar file on your classpath or in the extensions directory. Change your classpath to make sure you've got the javax.mail classes as well as the com.sun.mail classes.
Matthew X. Brown
Ranch Hand

Joined: Nov 08, 2000
Posts: 165
You also need to make sure you have the activation.jar in your path
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java Mail problem