Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Java Mailing Service (http://www.go4expert.com/forums/java-mailing-service-t16483/)

adroit89 10Mar2009 08:47

Java Mailing Service
hi guys...i am presently working on my mini-project in my college...and a module of it requires the use of java mailing service...i need to send a mail using SMTP protocol through my java application...i learnt that gmail can be used as a SMTP server to send mails...this is the code of my application...but when i am running this program i am getting a error stating NO CLASS FOUND javax.mail.Authenticator


import java.util.Properties; 
import javax.mail.Authenticator;
import javax.mail.Message; 
import javax.mail.MessagingException; 
import javax.mail.PasswordAuthentication; 
import javax.mail.Session; 
import javax.mail.Transport; 
import javax.mail.internet.InternetAddress; 
import javax.mail.internet.MimeMessage; 
  public class SendEmail
    public static void main(String args[]) throws Exception
          // Set the host smtp address 
          Properties props = new Properties(); 
          props.put("mail.smtp.starttls.enable", "true"); 
          props.put("mail.smtp.host", "smtp.gmail.com"); 
          props.put("mail.transport.protocol", "smtp"); 
          props.put("mail.smtp.auth", "true"); 
          Authenticator auth = new  SMTPAuthenticator("MY GMAIL ID","PASSWORD"); 
          Session session = Session.getDefaultInstance(props, auth); 
            // create a message 
          Message msg = new MimeMessage(session); 
            // set the from and to address 
          InternetAddress addressFrom = new InternetAddress("praveen"); 
          InternetAddress addressTo = new InternetAddress("adroit89@yahoo.co.in"); 
          msg.setRecipient(Message.RecipientType.TO, addressTo); 
          // Setting the Subject and Content Type 
          msg.setContent("hiiii", "text/html"); 
    * SimpleAuthenticator is used to do simple authentication when the SMTP
    * server requires it.
    public static class SMTPAuthenticator extends javax.mail.Authenticator
          private String username; 
          private String password; 
          public SMTPAuthenticator(String username, String password)
              this.username = username; 
              this.password = password; 
          public PasswordAuthentication getPasswordAuthentication()
              return new PasswordAuthentication(username, password); 

All times are GMT +5.5. The time now is 14:53.