之前采集好了好多QQ邮箱,想通过程序把邮件发出去,但是各大邮箱限制太多,一发就进垃圾邮箱,还有就是发的太多了就直接封ip了,发也发不出去。能成功发出去三四封就不错了……
所以想通过登陆wap版的qq模拟进行发信,开始以为成功了。后来发现也不行,发了几封之后的邮件都跑到草稿箱里面了……
现在放出获取联系人的代码,希望对有心人有所帮助
PS:代码比较简陋没有经过整理,但是确实可以完成登录QQ邮箱并获取联系人信息,如果朋友想解析出联系人,可以使用jsoup或者正则
import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.CookieStore; import org.apache.http.client.HttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.AbstractHttpClient; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; import org.apache.http.protocol.HTTP; import org.apache.http.util.EntityUtils; /** * * * @author www.kaedeen.com * */ public class GetContactList { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String userName="XXXXX@qq.com"; String passWord="PASSWORD"; //0.确定host String host=getQQMailHost(); //1.登陆 String sid=""; HttpClient httpClient = new DefaultHttpClient(); String url="http://"+host+"/cgi-bin/login"; Listnvps = new ArrayList (); nvps.add(new BasicNameValuePair("device", "")); nvps.add(new BasicNameValuePair("f", "xhtml")); nvps.add(new BasicNameValuePair("tfcont", "")); nvps.add(new BasicNameValuePair("uin", userName)); nvps.add(new BasicNameValuePair("aliastype", "@qq.com")); nvps.add(new BasicNameValuePair("pwd", passWord)); nvps.add(new BasicNameValuePair("btlogin", "登陆")); nvps.add(new BasicNameValuePair("mss", "")); HttpPost httpPost =new HttpPost(url); HttpResponse httpResponse=null;//登陆请求返回信息 String reponseBody=""; try { httpPost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); httpPost.addHeader("Referer", "http://w.mail.qq.com/cgi-bin/loginpage?f=xhtml"); httpPost.addHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.2) Gecko/2008070208 Firefox/3.0.1 "); httpResponse=httpClient.execute(httpPost); HttpEntity resEntity = httpResponse.getEntity(); reponseBody=EntityUtils.toString(resEntity); } catch (Exception e) { e.printStackTrace(); } finally { httpPost.abort(); } Pattern pattern = Pattern.compile("/today\?sid\=(.*)&first=1"); Matcher m = pattern.matcher(reponseBody); if (m.find()) { sid=m.group(1); } else { System.out.println("获取sid失败!"); } //2、获取联系人 HttpGet httpget =new HttpGet("http://"+host+"/cgi-bin/addr_listall?sid="+sid); httpget.setHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.2) Gecko/2008070208 Firefox/3.0.1 "); try { //简单复用之前变量 httpResponse = httpClient.execute(httpget); HttpEntity resEntity = httpResponse.getEntity(); reponseBody=EntityUtils.toString(resEntity); System.out.println(reponseBody); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 获取动态host地址 * @return */ public static String getQQMailHost() { String host=""; HttpClient httpClient = new DefaultHttpClient(); String url="http://w.mail.qq.com/cgi-bin/loginpage?f=xhtml"; HttpGet httpget =new HttpGet(url); httpget.setHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.2) Gecko/2008070208 Firefox/3.0.1 "); try { HttpResponse httpResponse = httpClient.execute(httpget); Pattern pattern = Pattern.compile("Set-Cookie: edition\=(.*); Domain=.mail.qq.com; Path=/; Expires"); Matcher m = pattern.matcher(httpResponse.toString()); if (m.find()) { host=m.group(1); } else { System.out.println("获取host失败!"); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return host; } }