G
gast
Gast
Code:
package javamail;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import java.io.*;
public class Test{
public static void postMail( String recipient,String subject,String message, String from )throws MessagingException{
Properties props = new Properties();
props.put( "mail.smtp.auth","true" );
Session session = Session.getDefaultInstance( props );
Message msg = new MimeMessage( session );
InternetAddress addressFrom = new InternetAddress( from );
msg.setFrom( addressFrom );
InternetAddress addressTo = new InternetAddress( recipient );
msg.setRecipient( Message.RecipientType.TO, addressTo );
msg.setSubject( subject );
msg.setContent( message, "text/plain" );
Transport.send( msg );
}
public static void getMail( String host, String user, String passwd )throws Exception{
Session session = Session.getDefaultInstance( new Properties() );
Store store = session.getStore( "pop3" );
store.connect( host, user, passwd );
Folder folder = store.getFolder( "INBOX" );
folder.open( Folder.READ_ONLY );
Message message[] = folder.getMessages();
for ( int i = 0; i < message.length; i++ )
{
Message m = message[i];
System.out.println( "Nachricht: " + i );
System.out.println( "From: " + m.getFrom()[0] );
System.out.println( "Subject: " + m.getSubject() );
Multipart mp = (Multipart)m.getContent();
for ( int j = 0; j < mp.getCount(); j++ )
{
Part part = mp.getBodyPart( j );
String disposition = part.getDisposition();
if ( disposition == null )
{
MimeBodyPart mimePart = (MimeBodyPart)part;
if ( mimePart.isMimeType("text/plain") )
{
BufferedReader in = new BufferedReader(
new InputStreamReader(mimePart.getInputStream()) );
String line;
while ( (line=in.readLine()) != null )
System.out.println( line );
}
}
}
}
folder.close( false );
store.close();
}
public static void main( String args[] ) throws Exception{
getMail( "pop3.web.de","<<<<<<user<<<<<<<", "<<<<password<<<<<" );
postMail( "<<<<<<user mail addi<<<","Tolles Buch","Wow. Das Buch ist schön zu lesen","<<<<usermailaddi<<<<<");
}
}
Wieso funktioniert der oben genannte Quellcode nicht? Er stammt aus JAVA ist auch eine Insel, jedoch ergibt schon das Compilieren ne Fehlermeldung:
Fehler:" 000013: getDefaultInstance(java.util.Properties,javax.mail.Authenticator) in javax.mail.Session cannot be applied to (java.util.Prperties)
Session session=Session.getDefaultInstance(props)
[Edit by foobar: Codetags eingefügt]