Avatar billede axe Nybegynder
07. februar 2007 - 12:22 Der er 2 kommentarer og
1 løsning

Hvilken version af jdk

Hvilen version af JDK kræves for at køre dette program, får følgende fejlbesked ved kørsel.jeg bruger 1.3

java.lang.NoClassDefFoundError: com/sun/mail/util/SharedByteArrayInputStream
    at rageout.classes.SendMailUsingAuthentication.postMail(SendMailUsingAuthentication.java:81)
    at rageout.classes.SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:61)
Exception in thread "main"

package rageout.classes;
/*
Some SMTP servers require a username and password authentication before you
can use their Server for Sending mail. This is most common with couple
of ISP's who provide SMTP Address to Send Mail.

This Program gives any example on how to do SMTP Authentication
(User and Password verification)

This is a free source code and is provided as it is without any warranties and
it can be used in any your code for free.

Author : Sudhir Ancha
*/

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

/*
  To use this program, change values for the following three constants,

    SMTP_HOST_NAME -- Has your SMTP Host Name
    SMTP_AUTH_USER -- Has your SMTP Authentication UserName
    SMTP_AUTH_PWD  -- Has your SMTP Authentication Password

  Next change values for fields

  emailMsgTxt  -- Message Text for the Email
  emailSubjectTxt  -- Subject for email
  emailFromAddress -- Email Address whose name will appears as "from" address

  Next change value for "emailList".
  This String array has List of all Email Addresses to Email Email needs to be sent to.


  Next to run the program, execute it as follows,

  SendMailUsingAuthentication authProg = new SendMailUsingAuthentication();

*/

public class SendMailUsingAuthentication
{

  private static final String SMTP_HOST_NAME = "mail1.stofanet.dk";
  private static final String SMTP_AUTH_USER = "1770817m001";
  private static final String SMTP_AUTH_PWD  = "vlot9024";

  private static final String emailMsgTxt      = "Online Order Confirmation Message. Also include the Tracking Number.";
  private static final String emailSubjectTxt  = "Order Confirmation Subject";
  private static final String emailFromAddress = "sudhir@javacommerce.com";

  // Add List of Email address to who email needs to be sent to
  private static final String[] emailList = {"mark@yahoo.com", "robin@javacommerce.com"};

  public static void main(String args[]) throws Exception
  {
    SendMailUsingAuthentication smtpMailSender = new SendMailUsingAuthentication();
    smtpMailSender.postMail( emailList, emailSubjectTxt, emailMsgTxt, emailFromAddress);
    System.out.println("Sucessfully Sent mail to All Users");
  }

  public void postMail( String recipients[ ], String subject,
                            String message , String from) throws MessagingException
  {
    boolean debug = false;

    //Set the host smtp address
    Properties props = new Properties();
    props.put("mail.smtp.host", SMTP_HOST_NAME);
    props.put("mail.smtp.auth", "true");

    Authenticator auth = new SMTPAuthenticator();
    Session session = Session.getDefaultInstance(props, auth);

    session.setDebug(debug);

    // create a message
    Message msg = new MimeMessage(session);

    // set the from and to address
    InternetAddress addressFrom = new InternetAddress(from);
    msg.setFrom(addressFrom);

    InternetAddress[] addressTo = new InternetAddress[recipients.length];
    for (int i = 0; i < recipients.length; i++)
    {
        addressTo[i] = new InternetAddress(recipients[i]);
    }
    msg.setRecipients(Message.RecipientType.TO, addressTo);


    // Setting the Subject and Content Type
    msg.setSubject(subject);
    msg.setContent(message, "text/plain");
    Transport.send(msg);
}


/**
* SimpleAuthenticator is used to do simple authentication
* when the SMTP server requires it.
*/
private class SMTPAuthenticator extends javax.mail.Authenticator
{

    public PasswordAuthentication getPasswordAuthentication()
    {
        String username = SMTP_AUTH_USER;
        String password = SMTP_AUTH_PWD;
        return new PasswordAuthentication(username, password);
    }
}

}
Avatar billede winners79 Nybegynder
07. februar 2007 - 13:09 #1
Kan du ikke bare bruge den nyeste? det er jo generelt det bedste.. de ældre java versioner har jo også sikkerheds huller etc.. den nyeste i øjeblikket er 1.6 også kaldet 6.0
Avatar billede axe Nybegynder
07. februar 2007 - 13:45 #2
nu får jeg følgende fejl besked fra tomcat serveren
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 javax.mail.Session.getTransport(Session.java:519)
    at javax.mail.Transport.send0(Transport.java:155)
    at javax.mail.Transport.send(Transport.java:81)
Avatar billede axe Nybegynder
07. februar 2007 - 16:52 #3
cvv
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester