无法在Android中使用Pop接收邮件 [英] Can't receive mails with Pop in Android

查看:109
本文介绍了无法在Android中使用Pop接收邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下代码示例通过Imap接收邮件:

I can receive my mails with Imap with this code sample :

URLName server = new URLName("imaps://" + username + ":"+ password + "@imap.gmail.com/INBOX");
    Session session = Session.getDefaultInstance(new Properties(), null);
    Folder folder = session.getFolder(server);
if (folder == null) 
{
    System.exit(0);
}
   folder.open(Folder.READ_ONLY);
   Message[] messages = folder.getMessages();

但是有时Imap不提供任何服务,在那个时候我想使用Pop,但是我无法在代码中使用它.使用接收邮件的其他代码与其他代码不同.但是在Android中,只有此代码有效.

But sometimes Imap doesn't give any service and at those times I want to use Pop but I couldn't use it with my code. It is different the other codes for using receive mail. But in Android only this code is working.

要在Pop上使用该代码,我应该更改哪些内容?

What should I change in this code to work with Pop?

推荐答案

首先,有一个不错的URLName构造函数,它将所有组件作为单独的参数,因此您不必进行字符串串联.

First, there's a nice URLName constructor that takes all the component pieces as separate parameters, so you don't have to do string concatenation.

从IMAP切换到POP3需要更改协议名称和主机名.有关示例,请参见 JavaMail常见问题解答.协议名称为"pop3s",主机名称为"pop.gmail.com".

Switch from IMAP to POP3 requires changing the protocol name as well as the host name. See the JavaMail FAQ for examples. The protocol name is "pop3s" and the host name is "pop.gmail.com".

最后,您应该使用Session.getInstance而不是Session.getDefaultInstance.比较这两种方法的javadocs,以了解原因.

Finally, you should use Session.getInstance instead of Session.getDefaultInstance. Compare the javadocs for the two methods to understand why.

这篇关于无法在Android中使用Pop接收邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆