MailSend.cpp
上传用户:lmxny16666
上传日期:2021-03-03
资源大小:16k
文件大小:4k
源码类别:

Email服务器

开发平台:

Visual C++

  1. // MailSend.cpp: implementation of the CMailSend class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "163_COM.h"
  6. #include "MailSend.h"
  7. #include "WTString.h"
  8. #include "Request.h"
  9. #include "HttpRequest.h"
  10. #include "HttpClient.h"
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char THIS_FILE[]=__FILE__;
  14. #define new DEBUG_NEW
  15. #endif
  16. //////////////////////////////////////////////////////////////////////
  17. // Construction/Destruction
  18. //////////////////////////////////////////////////////////////////////
  19. CMailSend::CMailSend()
  20. {
  21. }
  22. extern "C" __declspec(dllexport)
  23. long __stdcall mySendMail(void *lpTask,void *lpThreadContact)
  24. {
  25. CString str;
  26. int at;
  27. int end;
  28. //取得传参中相应自字段的值
  29. CRequest q;
  30. q.Parse((LPCTSTR)lpTask);
  31. CString strUserName = q.QueryString("UserName");
  32. CString strUserPass = q.QueryString("UserPass");
  33. CString strMailBody = q.QueryString("MailBody");
  34. CString strMailTo = q.QueryString("MailTo");
  35. CString strSubject = q.QueryString("Subject");
  36. CString strURL;
  37. CWTString wts;
  38. CHttpClient ant;
  39. CString strFormData;
  40. ant.m_strContentType = "application/x-www-form-urlencoded";
  41. ant.m_strReferer = "http://mail.163.com/";
  42. strFormData = "verifycookie=1&style=35&product=mail163&username="+strUserName;
  43. strFormData += "&password=";
  44. strFormData += wts.URLEncode(strUserPass);
  45. strFormData += "&selType=jy&%B5%C7%C2%BC%D3%CA%CF%E4=";
  46. 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";
  47. ant.m_strOptional = strFormData;
  48. ant.Request("POST",strURL);
  49. if(ant.m_strBody.IsEmpty()){
  50. return -600;
  51. }
  52. CString strPath;
  53. CString strFile;
  54. GetModulePath(strPath);
  55. strFile = strPath+"data\log1.htm";
  56. ant.SaveResponse(strFile);
  57. ////////////////////////////第二步
  58. ant.m_cookie.m_server=".163.com";
  59. ant.m_strOptional="";
  60. ant.m_iRequestLength = 0;
  61. strURL = "http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=35&username="+strUserName;
  62. ant.m_strReferer = strURL;
  63. CString strcookie="cookie:";
  64. for (int i=0;i<ant.m_cookie.m_list.GetSize();i++)
  65. {
  66. strcookie+=ant.m_cookie.m_list.GetAt(i);
  67. if (i!=ant.m_cookie.m_list.GetSize()-1)
  68. {
  69. strcookie+=";";
  70. }
  71. }
  72. ant.AddRequestHeader(strcookie);
  73. ant.Request("GET",strURL);
  74. if(ant.m_strBody.IsEmpty()){
  75. return -601;
  76. }
  77. strFile = strPath +"data\log2.htm";
  78. ant.SaveResponse(strFile);
  79. //解析出标志字符串
  80. CString strSid;
  81. strcookie="cookie:"+ant.m_cookie.m_list.GetAt(0);
  82. ant.AddRequestHeader(strcookie);
  83. at = ant.m_strBody.Find("href=");
  84. end = ant.m_strBody.Find(">",at);
  85. at += 6;
  86. end -=1;
  87. strURL = ant.m_strBody.Mid(at,end-at);   //登陆地址
  88. q.Parse(strURL);
  89. strSid = q.QueryString("sid");
  90. at = strURL.Find(".com");     
  91.     str = strURL.Mid(0,at+5);
  92. ant.m_strOptional="";
  93. ant.m_iRequestLength=0;    //请求数据为空
  94. ant.m_cookie.m_server = ".163.com";
  95. ant.Request("GET",strURL);
  96. if(ant.m_strBody.IsEmpty()){
  97. return -602;
  98. }
  99. //Get ComponseId
  100. CString strComposeID;
  101. strURL = str+"jy3/compose/main.jsp?sid="+strSid;//写信
  102. ant.m_strReferer = strURL;
  103. ant.m_strOptional = "";
  104. ant.Request("GET",strURL);
  105. if(ant.m_strBody.IsEmpty()){
  106. return -603;
  107. }
  108. at = ant.m_strBody.Find("composeId");
  109. strComposeID = ant.m_strBody.Mid(at);
  110. at = ant.m_strBody.Find("value=",at);
  111. end = ant.m_strBody.Find("/>",at);
  112. at += 7;
  113. end -=2;
  114. strComposeID = ant.m_strBody.Mid(at,end-at);
  115. strFormData = "composeId="+strComposeID+"&content=";
  116. strFormData+= wts.URLEncode(strMailBody);
  117. strFormData += "&isHtml=true&scheduleDate=&isSource=false&action=deliver&returnInfo=true";
  118. strFormData += "&attachment=0&attachinfo=&backURL=&autosave=false&orgAction=&verifyCode=&saveSentCopy=0";
  119. strFormData += "&account="+strUserName+"@163.com&to=";
  120. strFormData += wts.URLEncode(strMailTo);
  121. strFormData += "&cc=&bcc=&subject=";
  122. strFormData += wts.URLEncode(strSubject);
  123. strFormData += "&localAttach=&select=2009&select=10&select=31&select=17&select=43";
  124. strURL = str+ "jy3/compose/compose.jsp?sid="+strSid; //提交地址
  125. ant.m_strContentType = "application/x-www-form-urlencoded";
  126. ant.m_strOptional = strFormData;
  127. ant.m_strReferer = strURL;
  128. ant.Request("POST",strURL);
  129. strFile = strPath + "data\log3.htm";
  130. ant.SaveResponse(strFile);
  131. if(ant.m_strBody.Find("邮件已成功发送")<1){
  132. return -604;
  133. }
  134. else
  135. return 0;
  136. }