java 使用 javamail 连接到 hotmail?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3069966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 00:12:52  来源:igfitidea点击:

Connect to hotmail with javamail?

javaemailjakarta-eejavamailhotmail

提问by Sebastien Lorber

I wonder if it is possible to connect to Hotmail with JavaMail?

我想知道是否可以使用 JavaMail 连接到 Hotmail?

I've tried this but it doesn't work, connection refused...

我试过这个,但它不起作用,连接被拒绝......

    String host = "pop3.live.com";
    String username = "[email protected]";
    String password = "rqetqetq";

    Session session;
    Store store;

    String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";

    Properties pop3Props = new Properties();

    pop3Props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
    pop3Props.setProperty("mail.pop3.socketFactory.fallback", "false");
    pop3Props.setProperty("mail.pop3.port",  "995");
    pop3Props.setProperty("mail.pop3.socketFactory.port", "995");

    URLName url = new URLName("pop3", host, 995, "", username, password);

    session = Session.getInstance(pop3Props, null);
    store = new POP3SSLStore(session, url);
    store.connect();

Anyone already succeeded to do this?

有人已经成功做到了吗?

采纳答案by Romain Hippeau

You could try this SourceForge project

你可以试试这个SourceForge 项目

MrPostman is an email gateway from local POP clients like Microsoft Outlook, Mozilla's mail client etc. to different web mail services like Yahoo and Hotmail.It is being designed for extensibility so is easy to add more web mail services to it.

MrPostman 是一个电子邮件网关,从本地 POP 客户端(如 Microsoft Outlook、Mozilla 的邮件客户端等)到不同的 Web 邮件服务(如 Yahoo 和 Hotmail)。它的设计具有可扩展性,因此很容易向其添加更多 Web 邮件服务。

回答by Timo

Hotmail now supports pop3 (through SSL).

Hotmail 现在支持 pop3(通过 SSL)。

Thus, you need the following settings:

因此,您需要以下设置:

pop3Props.setProperty("mail.pop3.ssl.enable", "true");

pop3Props.setProperty("mail.pop3.ssl.enable", "true");

For all other properties, you must add a "s" in the properties string (so it says "pop3s" instead of "pop3"):

对于所有其他属性,您必须在属性字符串中添加一个“s”(因此它显示为“pop3s”而不是“pop3”):

pop3Props.setProperty("mail.pop3s.socketFactory.class", SSL_FACTORY); pop3Props.setProperty("mail.pop3s.socketFactory.fallback", "false"); pop3Props.setProperty("mail.pop3s.port", "995"); pop3Props.setProperty("mail.pop3s.socketFactory.port", "995");

pop3Props.setProperty("mail.pop3s.socketFactory.class", SSL_FACTORY); pop3Props.setProperty("mail.pop3s.socketFactory.fallback", "false"); pop3Props.setProperty("mail.pop3s.port", "995"); pop3Props.setProperty("mail.pop3s.socketFactory.port", "995");

For me, the following code works nicely:

对我来说,以下代码效果很好:

String host = "pop3.live.com";
String username = "[email protected]";
String password = "rqetqetq";

Properties pop3Props = new Properties();
pop3Props.setProperty("mail.pop3s.port",  "995");

Session session = Session.getInstance(pop3Props, null);
Store store = session.getStore("pop3s");
store.connect(host, 995, username, password);