Avatar billede axe Nybegynder
11. februar 2007 - 21:55 Der er 10 kommentarer

Kan ikke få denne klasse til at virke

Compileren brokker sig ikke, det vises ingen fejl i Websshpere. får denne fejlbesked ved kørsel

java.lang.UnsupportedClassVersionError: com/sun/mail/util/LineInputStream (Unsupported major.minor version 48.0)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:695)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:133)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:319)
    at java.net.URLClassLoader.access$400(URLClassLoader.java:92)
    at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:677)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:238)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:514)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:441)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:446)
    at javax.mail.Session.loadProvidersFromStream(Session.java:828)
    at javax.mail.Session.loadProviders(Session.java:796)
    at javax.mail.Session.<init>(Session.java:81)
    at javax.mail.Session.getDefaultInstance(Session.java:163)
    at rageout.classes.SendMailUsingAuthentication.postMail(SendMailUsingAuthentication.java:76)
    at rageout.classes.SendMailUsingAuthentication.main(SendMailUsingAuthentication.java:61)
Exception in thread "main"


/*
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 = "myserver.smtphost.com";
  private static final String SMTP_AUTH_USER = "myusername";
  private static final String SMTP_AUTH_PWD  = "mypwd";

  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 arne_v Ekspert
11. februar 2007 - 21:59 #1
det lyder som om du har smidt en jar fil buildet med en nyere java version ind
i WebSphere som kører med en ældre java version
Avatar billede axe Nybegynder
12. februar 2007 - 01:13 #2
efter at have fjernet de nye activation.jar og mail.jar får jeg denne fejlbesked
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"
Avatar billede arne_v Ekspert
12. februar 2007 - 01:25 #3
jeg forstår ikke helt fejlen, da der ikke er nogen referenec til
com.sun.mail.util.SharedByteArrayInputStream i SendMailUsingAuthentication.postMail

men det kunne ligne noget SUN Java der er blevet blandet med noget IBM Java
Avatar billede axe Nybegynder
12. februar 2007 - 08:45 #4
jeg kan godt køre programmet på en tomcat server, men der går den i stå ved for løkken
Avatar billede axe Nybegynder
12. februar 2007 - 10:10 #5
har du en mail klasse med bruger og password validering
Avatar billede axe Nybegynder
12. februar 2007 - 14:35 #6
Så har jeg forsøgt med commons mail, den går istå ved 3

try {
            SimpleEmail email=new SimpleEmail();
            System.out.println("1");
            email.setHostName("mail1.stofanet.dk");
            System.out.println("2");
            email.setAuthentication("xxx","xxx");
            System.out.println("3");
            email.setFrom("o-bloch@mail1.stofanet.dk","ole");
            System.out.println("4");
            email.addTo("o-bloch@mail1.stofanet.dk");
            System.out.println("5");
            email.setSubject("hejsa");
            email.setMsg("hejsa tak for sidst");
            System.out.println("7");
            email.send();
            System.out.println("8");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
Avatar billede axe Nybegynder
12. februar 2007 - 15:14 #7
kan det skyldes min tomcat er en ver. 1.4
Avatar billede axe Nybegynder
12. februar 2007 - 15:50 #8
nu har jeg fået den op på 7 men den vil bare ikke email.send();
Avatar billede axe Nybegynder
13. februar 2007 - 11:28 #9
smid et svar så
Avatar billede arne_v Ekspert
06. maj 2007 - 22:58 #10
lig selv et svar og tag point tilbage
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