POP3_收取QQ邮箱邮件的问题
今天纠结了一天的时间,使用pop3协议收取qq邮箱中邮件时,因为一个特别坑爹的问题重新写n次,最后发现是因为qq邮箱设置了独立邮箱密码,必须的用独立邮箱密码登陆才行,/(ㄒoㄒ)/~~!!!!
但今天干的活也不能白干,所以发出来记录一下代码。
package com.lkb.thirdUtil.emailbank.test; import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*; public class MailExample { public static void main (String args[]) throws Exception { // Get system properties
Properties props = System.getProperties(); // Setup mail server
props.put("mail.pop3.host", "pop.qq.com");
props.put("mail.pop3.port", "995");
// Get session
props.put("mail.smtp.auth", "true"); //这样才能通过验证
props.put("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.pop3.socketFactory.fallback", "false");
props.setProperty("mail.pop3.socketFactory.port", "995"); MyAuthenticator myauth = new MyAuthenticator("*****@qq.com", "******");
Session session = Session.getDefaultInstance(props, myauth);
Store store = session.getStore("pop3");
store.connect();
//session.setDebug(true);
System.out.println("成功!");
Folder folder = store.getFolder("INBOX");
// 只读
folder.open(Folder.READ_ONLY);
Message[] mess=folder.getMessages();
for (Message message : mess) {
System.out.println(message.getSubject());
}
}
}
--------------------------------------------------------
package com.lkb.thirdUtil.emailbank.test; import javax.mail.PasswordAuthentication; class MyAuthenticator
extends javax.mail.Authenticator {
private String strUser;
private String strPwd;
public MyAuthenticator(String user, String password) {
this.strUser = user;
this.strPwd = password;
} protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(strUser, strPwd);
}
}
IMAP形式:
package com.lkb.thirdUtil.emailbank.test; import java.io.UnsupportedEncodingException;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Folder;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Store;
public class ImapProtocolImpl extends Authenticator
{
private Session session;
private PasswordAuthentication authentication; public ImapProtocolImpl(String username, String password)
{
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imap");
props.setProperty("mail.imap.host", "imap.qq.com");
props.setProperty("mail.imap.port", "993");
props.put("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.imap.socketFactory.fallback", "false");
props.setProperty("mail.imap.auth.login.disable", "true");
props.setProperty("mail.imap.auth.plain.disable","true"); authentication = new PasswordAuthentication(username, password);
session = Session.getInstance(props, this);
session.setDebug(true);
} @Override
public PasswordAuthentication getPasswordAuthentication()
{
return this.authentication;
} public void connect()
{
try
{
Store store = session.getStore();
store.connect();
Folder root = store.getDefaultFolder();
Folder inbox = root.getFolder("inbox");
inbox.open(Folder.READ_WRITE);
System.out.println(inbox.getMessageCount());
}
catch (MessagingException e)
{
try
{
byte[] buf = e.getMessage().getBytes("ISO-8859-1");
System.out.println(new String(buf, "GBK"));
}
catch (UnsupportedEncodingException e1)
{
e1.printStackTrace();
}
throw new RuntimeException("登录失败", e);
}
}
}
POP3_收取QQ邮箱邮件的问题的更多相关文章
- php 发送QQ邮箱邮件
这是我的源码比较简陋 https://www.lanzous.com/i2l7h8f 感谢 https://www.cnblogs.com/woider/p/6980456.html 下载phpmai ...
- win10自带邮箱如何使用?win10自带邮箱如何同步qq邮箱邮件?
win10自带邮箱如何使用? 相信很多小伙伴在登录win10自带的邮箱登录QQ邮箱时,显示同步失败或者登录超时,但又找不到相关的资料,下面是我自己邮箱的操作流程,小伙伴可以尝试一下,有什么问题留言即可 ...
- 技术笔记:Indy IdSMTP支持腾讯QQ邮箱邮件发送
1.腾讯QQ邮箱的授权码问题 因为腾讯邮箱折腾了个底朝天,其要搞什么授权码登录第三方客户端,否则会报这个错误: 'Error: 请使用授权码登录.详情请看: http://service.mail.q ...
- Python3+smtplib+poplib+imaplib实现发送和收取邮件(以qq邮箱为例)
一.说明 1.1 程序说明 (1)smtp是邮件发送协议:pop和imap都是邮件接收协议,两者的区别通常的说法是imap的操作会同步到邮箱服务器而pop不会,表现上我也不是很清楚 (2)本程序实现使 ...
- 规划收发你的邮件,使用qq邮箱接收阿里云企业邮邮件
使用qq邮箱接收阿里企业邮 首先管理员开通企业邮后会发来激活短信 根据短信提示打开https://qiye.aliyun.com企业邮登陆地址 使用短信提供的密码登陆邮箱 首次登陆时会让我们重设密码 ...
- outlook创建收信规则,将收到的所有邮件,转发到qq邮箱,然后删除
因为outlook默认只有400M的空间. 使用企业邮箱的时候,很快就满了. 本来是打算在qq邮箱中,添加其他邮箱来收取的. http://service.mail.qq.com/cgi-bin/he ...
- java mail使用qq邮箱发邮件的配置方法
最近自己折腾了下Java中利用mai发送QQ邮件 1.QQ邮箱设置 1.1 进去QQ邮箱-->设置-->账号-->进行设置如下图 2.foxmail设置(由于我要利用它收邮件) 2. ...
- Python编写邮件群发(qq邮箱)
#电子邮件操作 import poplib import smtplib from email.header import decode_header from email.mime.text imp ...
- C#发送Email邮件(实例:QQ邮箱和Gmail邮箱)
下面用到的邮件账号和密码都不是真实的,需要测试就换成自己的邮件账号. 需要引用: using System.Net.Mail; using System.Text; using System.Net; ...
随机推荐
- Git 操作指南
http://blog.csdn.net/troy__/article/details/40082657
- html canvas非正方旋转和缩放...写的大多是正方的有人表示一直看正方的看厌了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 从字节码的角度看Java内部类与外部类的互相访问
Java中non-static内部类为何可以访问外部类的变量?Java中外部类又为何可以访问内部类的private变量?这两个问题困扰过我一段时间,查了一些网上的答案,大多从“闭包”概念入手,理解起来 ...
- House Robber I & II & III
House Robber You are a professional robber planning to rob houses along a street. Each house has a c ...
- Plus One & Plus One Linked List
Given a non-negative number represented as an array of digits, plus one to the number. The digits ar ...
- memcache 键名的命名规则以及和memcached的区别
2014年3月27日 07:47:46 Keys---- Data stored by memcached is identified with the help of a key. A keyis ...
- PYTHON-range和xrange区别
range会根据输入,生成一个list. xrange功能类似,但生成的不是一个list,而是一个迭代器,每次调用是返回一个数字.这样比较节省内存.
- java采用zip方式实现String的压缩和解压缩CompressStringUtil类
CompressStringUtil类:不多说,直接贴代码: /** * 压缩 * * @param paramString * @return */ public static final byte ...
- java 捕获所有异常
1.) 通过捕获异常类型的基类Exception就可以处理所有类型的异常.(事实上还有其它的基类,但Exception是同编程活动相关的基类) 2.)因为Exception是与编程有关的所有异常类的基 ...
- Linix下修改mysql服务器编码
1. 找到mysql的配置文件,拷贝到etc目录下,第一步很重要 把/usr/share/doc/mysql-server-5.1.52/my-large.cnf 复制到 /etc/my.cnf 即用 ...