Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Nov 2009
    Messaggi
    755

    accesso tramite pop a server hotmail

    Salve,
    tramite il mio client mail in java riesco ad autenticarmi a server gmail,libero (tramite imap) e yahoo tramite pop3,mentre nonostante hotmail consenta anch'esso l'accesso tramite pop non riesco ad accedervi.
    La procedura che seguo è la seguente:
    codice:
    Properties props=System.getProperties();
    props.put("mail.pop3.port", "995");
    Store store = Session.getDefaultInstance(props, null).getStore("pop3");
    store.connect("pop3.live.com", "nomeAccount@hotmail.com", "relativaPassword");
    Fatto ciò non riesco ad accedervi ottenendo tale eccezzione:
    codice:
    javax.mail.AuthenticationFailedException: EOF on socket
            at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:208)
            at javax.mail.Service.connect(Service.java:295)
            at mail.Avvio.jButton1ActionPerformed(Avvio.java:257)
            at mail.Avvio.access$000(Avvio.java:18)
            at mail.Avvio$1.actionPerformed(Avvio.java:74)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
            at java.awt.Component.processMouseEvent(Component.java:6289)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
            at java.awt.Component.processEvent(Component.java:6054)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4652)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Component.dispatchEvent(Component.java:4482)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
            at java.awt.Container.dispatchEventImpl(Container.java:2085)
            at java.awt.Window.dispatchEventImpl(Window.java:2478)
            at java.awt.Component.dispatchEvent(Component.java:4482)
            at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
            at java.awt.EventQueue.access$000(EventQueue.java:85)
            at java.awt.EventQueue$1.run(EventQueue.java:603)
            at java.awt.EventQueue$1.run(EventQueue.java:601)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
            at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
            at java.awt.EventQueue$2.run(EventQueue.java:617)
            at java.awt.EventQueue$2.run(EventQueue.java:615)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    dove Avvio.java:257 è la riga:
    codice:
    store.connect("pop3.live.com", "nomeAccount@hotmail.com", "relativaPassword");
    dunque,dove sbaglio?come posso risolvere?

  2. #2
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    spulciando in javamail:

    http://www.oracle.com/technetwork/ja...7.html#hotmail

    La classe usata è inclusa nelle demo di javamail:
    codice:
    import java.util.*;
    import java.io.*;
    import javax.mail.*;
    import javax.mail.event.*;
    import javax.mail.internet.*;
    
    /*
     * Demo app that exercises the Message interfaces.
     * Show information about and contents of messages.
     *
     * @author John Mani
     * @author Bill Shannon
     */
    
    public class msgshow {
    
        static String protocol;
        static String host = null;
        static String user = null;
        static String password = null;
        static String mbox = null;
        static String url = null;
        static int port = -1;
        static boolean verbose = false;
        static boolean debug = false;
        static boolean showStructure = false;
        static boolean showMessage = false;
        static boolean showAlert = false;
        static boolean saveAttachments = false;
        static int attnum = 1;
    
        public static void main(String argv[]) {
    	int msgnum = -1;
    	int optind;
    	InputStream msgStream = System.in;
    
    	for (optind = 0; optind < argv.length; optind++) {
    	    if (argv[optind].equals("-T")) {
    		protocol = argv[++optind];
    	    } else if (argv[optind].equals("-H")) {
    		host = argv[++optind];
    	    } else if (argv[optind].equals("-U")) {
    		user = argv[++optind];
    	    } else if (argv[optind].equals("-P")) {
    		password = argv[++optind];
    	    } else if (argv[optind].equals("-v")) {
    		verbose = true;
    	    } else if (argv[optind].equals("-D")) {
    		debug = true;
    	    } else if (argv[optind].equals("-f")) {
    		mbox = argv[++optind];
    	    } else if (argv[optind].equals("-L")) {
    		url = argv[++optind];
    	    } else if (argv[optind].equals("-p")) {
    		port = Integer.parseInt(argv[++optind]);
    	    } else if (argv[optind].equals("-s")) {
    		showStructure = true;
    	    } else if (argv[optind].equals("-S")) {
    		saveAttachments = true;
    	    } else if (argv[optind].equals("-m")) {
    		showMessage = true;
    	    } else if (argv[optind].equals("-a")) {
    		showAlert = true;
    	    } else if (argv[optind].equals("--")) {
    		optind++;
    		break;
    	    } else if (argv[optind].startsWith("-")) {
    		System.out.println(
    "Usage: msgshow [-L url] [-T protocol] [-H host] [-p port] [-U user]");
    		System.out.println(
    "\t[-P password] [-f mailbox] [msgnum] [-v] [-D] [-s] [-S] [-a]");
    		System.out.println(
    "or     msgshow -m [-v] [-D] [-s] [-S] [-f msg-file]");
    		System.exit(1);
    	    } else {
    		break;
    	    }
    	}
    
    	try {
    	    if (optind < argv.length)
    		 msgnum = Integer.parseInt(argv[optind]);
    
    	    // Get a Properties object
    	    Properties props = System.getProperties();
    
    	    // Get a Session object
    	    Session session = Session.getInstance(props, null);
    	    session.setDebug(debug);
    
    	    if (showMessage) {
    		MimeMessage msg;
    		if (mbox != null)
    		    msg = new MimeMessage(session,
    			new BufferedInputStream(new FileInputStream(mbox)));
    		else
    		    msg = new MimeMessage(session, msgStream);
    		dumpPart(msg);
    		System.exit(0);
    	    }
    
    	    // Get a Store object
    	    Store store = null;
    	    if (url != null) {
    		URLName urln = new URLName(url);
    		store = session.getStore(urln);
    		if (showAlert) {
    		    store.addStoreListener(new StoreListener() {
    			public void notification(StoreEvent e) {
    			    String s;
    			    if (e.getMessageType() == StoreEvent.ALERT)
    				s = "ALERT: ";
    			    else
    				s = "NOTICE: ";
    			    System.out.println(s + e.getMessage());
    			}
    		    });
    		}
    		store.connect();
    	    } else {
    		if (protocol != null)		
    		    store = session.getStore(protocol);
    		else
    		    store = session.getStore();
    
    		// Connect
    		if (host != null || user != null || password != null)
    		    store.connect(host, port, user, password);
    		else
    		    store.connect();
    	    }
    	    
    
    	    // Open the Folder
    
    	    Folder folder = store.getDefaultFolder();
    	    if (folder == null) {
    		System.out.println("No default folder");
    		System.exit(1);
    	    }
    
    	    if (mbox == null)
    		mbox = "INBOX";
    	    folder = folder.getFolder(mbox);
    	    if (folder == null) {
    		System.out.println("Invalid folder");
    		System.exit(1);
    	    }
    
    	    // try to open read/write and if that fails try read-only
    	    try {
    		folder.open(Folder.READ_WRITE);
    	    } catch (MessagingException ex) {
    		folder.open(Folder.READ_ONLY);
    	    }
    	    int totalMessages = folder.getMessageCount();
    
    	    if (totalMessages == 0) {
    		System.out.println("Empty folder");
    		folder.close(false);
    		store.close();
    		System.exit(1);
    	    }
    
    	    if (verbose) {
    		int newMessages = folder.getNewMessageCount();
    		System.out.println("Total messages = " + totalMessages);
    		System.out.println("New messages = " + newMessages);
    		System.out.println("-------------------------------");
    	    }
    
    	    if (msgnum == -1) {
    		// Attributes & Flags for all messages ..
    		Message[] msgs = folder.getMessages();
    
    		// Use a suitable FetchProfile
    		FetchProfile fp = new FetchProfile();
    		fp.add(FetchProfile.Item.ENVELOPE);
    		fp.add(FetchProfile.Item.FLAGS);
    		fp.add("X-Mailer");
    		folder.fetch(msgs, fp);
    
    		for (int i = 0; i < msgs.length; i++) {
    		    System.out.println("--------------------------");
    		    System.out.println("MESSAGE #" + (i + 1) + ":");
    		    dumpEnvelope(msgs[i]);
    		    // dumpPart(msgs[i]);
    		}
    	    } else {
    		System.out.println("Getting message number: " + msgnum);
    		Message m = null;
    		
    		try {
    		    m = folder.getMessage(msgnum);
    		    dumpPart(m);
    		} catch (IndexOutOfBoundsException iex) {
    		    System.out.println("Message number out of range");
    		}
    	    }
    
    	    folder.close(false);
    	    store.close();
    	} catch (Exception ex) {
    	    System.out.println("Oops, got exception! " + ex.getMessage());
    	    ex.printStackTrace();
    	    System.exit(1);
    	}
    	System.exit(0);
        }
    
        public static void dumpPart(Part p) throws Exception {
    	if (p instanceof Message)
    	    dumpEnvelope((Message)p);
    
    	/** Dump input stream .. 
    
    	InputStream is = p.getInputStream();
    	// If "is" is not already buffered, wrap a BufferedInputStream
    	// around it.
    	if (!(is instanceof BufferedInputStream))
    	    is = new BufferedInputStream(is);
    	int c;
    	while ((c = is.read()) != -1)
    	    System.out.write(c);
    
    	**/
    
    	String ct = p.getContentType();
    	try {
    	    pr("CONTENT-TYPE: " + (new ContentType(ct)).toString());
    	} catch (ParseException pex) {
    	    pr("BAD CONTENT-TYPE: " + ct);
    	}
    	String filename = p.getFileName();
    	if (filename != null)
    	    pr("FILENAME: " + filename);
    
    	/*
    	 * Using isMimeType to determine the content type avoids
    	 * fetching the actual content data until we need it.
    	 */
    	if (p.isMimeType("text/plain")) {
    	    pr("This is plain text");
    	    pr("---------------------------");
    	    if (!showStructure && !saveAttachments)
    		System.out.println((String)p.getContent());
    	} else if (p.isMimeType("multipart/*")) {
    	    pr("This is a Multipart");
    	    pr("---------------------------");
    	    Multipart mp = (Multipart)p.getContent();
    	    level++;
    	    int count = mp.getCount();
    	    for (int i = 0; i < count; i++)
    		dumpPart(mp.getBodyPart(i));
    	    level--;
    	} else if (p.isMimeType("message/rfc822")) {
    	    pr("This is a Nested Message");
    	    pr("---------------------------");
    	    level++;
    	    dumpPart((Part)p.getContent());
    	    level--;
    	} else {
    	    if (!showStructure && !saveAttachments) {
    		/*
    		 * If we actually want to see the data, and it's not a
    		 * MIME type we know, fetch it and check its Java type.
    		 */
    		Object o = p.getContent();
    		if (o instanceof String) {
    		    pr("This is a string");
    		    pr("---------------------------");
    		    System.out.println((String)o);
    		} else if (o instanceof InputStream) {
    		    pr("This is just an input stream");
    		    pr("---------------------------");
    		    InputStream is = (InputStream)o;
    		    int c;
    		    while ((c = is.read()) != -1)
    			System.out.write(c);
    		} else {
    		    pr("This is an unknown type");
    		    pr("---------------------------");
    		    pr(o.toString());
    		}
    	    } else {
    		// just a separator
    		pr("---------------------------");
    	    }
    	}
    
    	/*
    	 * If we're saving attachments, write out anything that
    	 * looks like an attachment into an appropriately named
    	 * file.  Don't overwrite existing files to prevent
    	 * mistakes.
    	 */
    	if (saveAttachments && level != 0 && !p.isMimeType("multipart/*")) {
    	    String disp = p.getDisposition();
    	    // many mailers don't include a Content-Disposition
    	    if (disp == null || disp.equalsIgnoreCase(Part.ATTACHMENT)) {
    		if (filename == null)
    		    filename = "Attachment" + attnum++;
    		pr("Saving attachment to file " + filename);
    		try {
    		    File f = new File(filename);
    		    if (f.exists())
    			// XXX - could try a series of names
    			throw new IOException("file exists");
    		    ((MimeBodyPart)p).saveFile(f);
    		} catch (IOException ex) {
    		    pr("Failed to save attachment: " + ex);
    		}
    		pr("---------------------------");
    	    }
    	}
        }
    
        public static void dumpEnvelope(Message m) throws Exception {
    	pr("This is the message envelope");
    	pr("---------------------------");
    	Address[] a;
    	// FROM 
    	if ((a = m.getFrom()) != null) {
    	    for (int j = 0; j < a.length; j++)
    		pr("FROM: " + a[j].toString());
    	}
    
    	// REPLY TO
    	if ((a = m.getReplyTo()) != null) {
    	    for (int j = 0; j < a.length; j++)
    		pr("REPLY TO: " + a[j].toString());
    	}
    
    	// TO
    	if ((a = m.getRecipients(Message.RecipientType.TO)) != null) {
    	    for (int j = 0; j < a.length; j++) {
    		pr("TO: " + a[j].toString());
    		InternetAddress ia = (InternetAddress)a[j];
    		if (ia.isGroup()) {
    		    InternetAddress[] aa = ia.getGroup(false);
    		    for (int k = 0; k < aa.length; k++)
    			pr("  GROUP: " + aa[k].toString());
    		}
    	    }
    	}
    
    	// SUBJECT
    	pr("SUBJECT: " + m.getSubject());
    
    	// DATE
    	Date d = m.getSentDate();
    	pr("SendDate: " +
    	    (d != null ? d.toString() : "UNKNOWN"));
    
    	// FLAGS
    	Flags flags = m.getFlags();
    	StringBuffer sb = new StringBuffer();
    	Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags
    
    	boolean first = true;
    	for (int i = 0; i < sf.length; i++) {
    	    String s;
    	    Flags.Flag f = sf[i];
    	    if (f == Flags.Flag.ANSWERED)
    		s = "\\Answered";
    	    else if (f == Flags.Flag.DELETED)
    		s = "\\Deleted";
    	    else if (f == Flags.Flag.DRAFT)
    		s = "\\Draft";
    	    else if (f == Flags.Flag.FLAGGED)
    		s = "\\Flagged";
    	    else if (f == Flags.Flag.RECENT)
    		s = "\\Recent";
    	    else if (f == Flags.Flag.SEEN)
    		s = "\\Seen";
    	    else
    		continue;	// skip it
    	    if (first)
    		first = false;
    	    else
    		sb.append(' ');
    	    sb.append(s);
    	}
    
    	String[] uf = flags.getUserFlags(); // get the user flag strings
    	for (int i = 0; i < uf.length; i++) {
    	    if (first)
    		first = false;
    	    else
    		sb.append(' ');
    	    sb.append(uf[i]);
    	}
    	pr("FLAGS: " + sb.toString());
    
    	// X-MAILER
    	String[] hdrs = m.getHeader("X-Mailer");
    	if (hdrs != null)
    	    pr("X-Mailer: " + hdrs[0]);
    	else
    	    pr("X-Mailer NOT available");
        }
    
        static String indentStr = "                                               ";
        static int level = 0;
    
        /**
         * Print a, possibly indented, string.
         */
        public static void pr(String s) {
    	if (showStructure)
    	    System.out.print(indentStr.substring(0, level * 2));
    	System.out.println(s);
        }
    }
    la cosa che salta all'occhio è pop3s invece di pop3 (poi sulla specifica della porta non mi sbilancio)
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.