MailSend.cpp
资源名称:163_com.rar [点击查看]
上传用户:lmxny16666
上传日期:2021-03-03
资源大小:16k
文件大小:4k
源码类别:
Email服务器
开发平台:
Visual C++
- // MailSend.cpp: implementation of the CMailSend class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "163_COM.h"
- #include "MailSend.h"
- #include "WTString.h"
- #include "Request.h"
- #include "HttpRequest.h"
- #include "HttpClient.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CMailSend::CMailSend()
- {
- }
- extern "C" __declspec(dllexport)
- long __stdcall mySendMail(void *lpTask,void *lpThreadContact)
- {
- CString str;
- int at;
- int end;
- //取得传参中相应自字段的值
- CRequest q;
- q.Parse((LPCTSTR)lpTask);
- CString strUserName = q.QueryString("UserName");
- CString strUserPass = q.QueryString("UserPass");
- CString strMailBody = q.QueryString("MailBody");
- CString strMailTo = q.QueryString("MailTo");
- CString strSubject = q.QueryString("Subject");
- CString strURL;
- CWTString wts;
- CHttpClient ant;
- CString strFormData;
- ant.m_strContentType = "application/x-www-form-urlencoded";
- ant.m_strReferer = "http://mail.163.com/";
- strFormData = "verifycookie=1&style=35&product=mail163&username="+strUserName;
- strFormData += "&password=";
- strFormData += wts.URLEncode(strUserPass);
- strFormData += "&selType=jy&%B5%C7%C2%BC%D3%CA%CF%E4=";
- strURL = "http://reg.163.com//login.jsp?type=1&url=http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D35";
- ant.m_strOptional = strFormData;
- ant.Request("POST",strURL);
- if(ant.m_strBody.IsEmpty()){
- return -600;
- }
- CString strPath;
- CString strFile;
- GetModulePath(strPath);
- strFile = strPath+"data\log1.htm";
- ant.SaveResponse(strFile);
- ////////////////////////////第二步
- ant.m_cookie.m_server=".163.com";
- ant.m_strOptional="";
- ant.m_iRequestLength = 0;
- strURL = "http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=35&username="+strUserName;
- ant.m_strReferer = strURL;
- CString strcookie="cookie:";
- for (int i=0;i<ant.m_cookie.m_list.GetSize();i++)
- {
- strcookie+=ant.m_cookie.m_list.GetAt(i);
- if (i!=ant.m_cookie.m_list.GetSize()-1)
- {
- strcookie+=";";
- }
- }
- ant.AddRequestHeader(strcookie);
- ant.Request("GET",strURL);
- if(ant.m_strBody.IsEmpty()){
- return -601;
- }
- strFile = strPath +"data\log2.htm";
- ant.SaveResponse(strFile);
- //解析出标志字符串
- CString strSid;
- strcookie="cookie:"+ant.m_cookie.m_list.GetAt(0);
- ant.AddRequestHeader(strcookie);
- at = ant.m_strBody.Find("href=");
- end = ant.m_strBody.Find(">",at);
- at += 6;
- end -=1;
- strURL = ant.m_strBody.Mid(at,end-at); //登陆地址
- q.Parse(strURL);
- strSid = q.QueryString("sid");
- at = strURL.Find(".com");
- str = strURL.Mid(0,at+5);
- ant.m_strOptional="";
- ant.m_iRequestLength=0; //请求数据为空
- ant.m_cookie.m_server = ".163.com";
- ant.Request("GET",strURL);
- if(ant.m_strBody.IsEmpty()){
- return -602;
- }
- //Get ComponseId
- CString strComposeID;
- strURL = str+"jy3/compose/main.jsp?sid="+strSid;//写信
- ant.m_strReferer = strURL;
- ant.m_strOptional = "";
- ant.Request("GET",strURL);
- if(ant.m_strBody.IsEmpty()){
- return -603;
- }
- at = ant.m_strBody.Find("composeId");
- strComposeID = ant.m_strBody.Mid(at);
- at = ant.m_strBody.Find("value=",at);
- end = ant.m_strBody.Find("/>",at);
- at += 7;
- end -=2;
- strComposeID = ant.m_strBody.Mid(at,end-at);
- strFormData = "composeId="+strComposeID+"&content=";
- strFormData+= wts.URLEncode(strMailBody);
- strFormData += "&isHtml=true&scheduleDate=&isSource=false&action=deliver&returnInfo=true";
- strFormData += "&attachment=0&attachinfo=&backURL=&autosave=false&orgAction=&verifyCode=&saveSentCopy=0";
- strFormData += "&account="+strUserName+"@163.com&to=";
- strFormData += wts.URLEncode(strMailTo);
- strFormData += "&cc=&bcc=&subject=";
- strFormData += wts.URLEncode(strSubject);
- strFormData += "&localAttach=&select=2009&select=10&select=31&select=17&select=43";
- strURL = str+ "jy3/compose/compose.jsp?sid="+strSid; //提交地址
- ant.m_strContentType = "application/x-www-form-urlencoded";
- ant.m_strOptional = strFormData;
- ant.m_strReferer = strURL;
- ant.Request("POST",strURL);
- strFile = strPath + "data\log3.htm";
- ant.SaveResponse(strFile);
- if(ant.m_strBody.Find("邮件已成功发送")<1){
- return -604;
- }
- else
- return 0;
- }