#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    1
    Rep Power
    0

    java mail compile problem


    I was wondering if someone can enlighten me as to what jar file I am missing. I assume that this can be figured out from my error message. I personally can not seem to figure it out. Thanks for the help!

    +++ this is just the top half of the code.. directly from sun +++

    import javax.mail.*;
    import javax.mail.internet.*;
    import java.util.*;

    public class SendEmail {

    public static void SendEmail(String smtpServer, String to, String from, String subject, String body) {
    try {
    Properties props = System.getProperties();
    // -- Attaching to default Session, or we could start a new one --
    props.put("mail.myserver.net", smtpServer);
    Session session = Session.getDefaultInstance(props, null);


    ++++ and now the error--

    SendEmail.java:22: cannot resolve symbol
    symbol : method getDefaultInstance (java.util.Properties,<nulltype>)
    location: class Session
    Session session = Session.getDefaultInstance(props, null);
    ^
    SendEmail.java:24: cannot resolve symbol
    symbol : constructor MimeMessage (Session)
    location: class javax.mail.internet.MimeMessage
    Message msg = new MimeMessage(session);

    Thanks for your help in this issue.. !! you guys rule!

    wade
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    NE Pa.
    Posts
    96
    Rep Power
    14
    This compiles fine on my machine, once I added the catch that is, so I have to wonder if you are missing part of the JavaMail package or if your classpath is wrong somehow (I know it doesnt make a lot of sense)....You may want to try importing the javax.activation (The activation.jar from the jaf) really doesnt make sense though.

    I did notice a couple of other things about your code though that you may want to look at. First of all static? Ouch thats gonna hurt when people start getting each others mail! Remember static means all the variables belong to the class! So if two people go thru this at one time they could (& probably will) get each others messages.

    Secondly you're are missing a step in the props object. the code should be as such:

    java.util.Properties props = System.getProperties();
    props.put("mail.smtp.host", "localhost"); //default server is localhost
    props.put("mail.transport.protocol", "smtp");

    and you really should set the debug to false in the session as such:

    Session session = Session.getDefaultInstance(props, null);
    session.setDebug(false);

    Lastly is your naming convention here. Methods NEVER start with a capital letter, only objects so your SendMail method should be sendMail. I know it sounds picky but thats how its done so anyone can look at the code & know the difference between a method & an object.

    As to your compile problem, once again Im not sure whats up with that!
    DC Dalton
    DCD Designs
    SCJP

IMN logo majestic logo threadwatch logo seochat tools logo