• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Mail problem

 
Amin Rais
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You also need to make sure you have the activation.jar in your path
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic