OSDN Git Service

Success Send one email to gmail server
[tortoisegit/TortoiseGitJp.git] / src / Utils / HwSMTP.h
1 // HwSMTP.h: interface for the CHwSMTP class.\r
2 //\r
3 //////////////////////////////////////////////////////////////////////\r
4 \r
5 /*******************************************************************\r
6                 ËµÃ÷\r
7         1¡¢ÕâÊÇÎÒ×Ô¼ºÐ´µÄÒ»¸öÀûÓÃSMTP·þÎñÆ÷·¢ËÍÓʼþµÄÀ࣬¿ÉÒÔʵÏÖ¸½¼þµÄ\r
8 ·¢ËÍ¡£\r
9         2¡¢ÔÚ InitInstance() º¯Êýµ÷Óà\r
10         if (!AfxSocketInit())\r
11         {\r
12                 AfxMessageBox(IDP_SOCKETS_INIT_FAILED);\r
13                 return FALSE;\r
14         }\r
15         ÔÚ ExitInstance () Öе÷Óà::WSACleanup ();\r
16 *******************************************************************/\r
17 \r
18 /****************************************************************************************************************\r
19 Ͷ¸å˵Ã÷£º\r
20 ****************************************************************************************************************/\r
21 #define NOTE_SpeedPostMail \\r
22 _T("\\r
23                         ¡¾Èí¼þÃû³Æ¡¿\r\n\\r
24         ÎÞÐëSMTP·þÎñÆ÷ÖÐתֱ½Ó½«E-Mailµç×ÓÓʼþ·¢Ë͵½¶Ô·½ÓÊÏä\r\n\\r
25                         ¡¾°æ    ±¾¡¿\r\n\\r
26         1.0.0\r\n\\r
27                         ¡¾²Ù×÷ϵͳ¡¿\r\n\\r
28         Windows ×ÀÃæϵÁÐ\r\n\\r
29                         ¡¾×÷    Õß¡¿\r\n\\r
30         Ð»ºìΰ ¡¤ chrys ¡¤ chrys@163.com ¡¤ http://www.viction.net\r\n\\r
31                         ¡¾Èí¼þ˵Ã÷¡¿\r\n\\r
32         ´ó¼ÒÒ»¶¨ÊìϤFoxmailÖеġ°ÌØ¿ìרµÝ¡±£¬ËüÄÜÖ±½Ó½«Óʼþ·¢Ë͵½¶Ô·½µÄÓʼþ·þÎñÆ÷ÖУ¬¶ø²»ÐèÒª¾­¹ýSMTP·þÎñÆ÷ÖÐת£¬\\r
33 ±¾´úÂ뽫ÏòÄãÆÊÎö¡°ÌØ¿ìרµÝ¡±·¢Ë͵ç×ÓÓʼþµÄ·½·¨¡£´úÂëÖÐÌṩÁËÍø¿¨ÐÅÏ¢»ñÈ¡À࣬¿ÉÒÔ»ñÈ¡±¾»úIPµØÖ·¡¢×ÓÍøÑÚÂë¡¢DNS¡¢\\r
34 Wins¡¢Íø¿¨MACµØÖ·µÈÏà¹ØÐÅÏ¢£»»¹ÌṩÁËSMTPЭÒé½âÎöÀ࣬¸ÃÀàʵÏÖÁËSMTP¿Í»§¶Ë¹¦ÄܵÄʵÏÖÀ࣬ʵÏÖµç×ÓÓʼþÊÕ·¢£»Base64±àÂëʵÏÖ\\r
35 ÁË×Ö·û±àÂëµÄ·½·¨¡£\r\n\\r
36         Äã¿ÉÒÔÈÎÒâÐ޸ĸ´ÖƱ¾´úÂ룬µ«Çë±£ÁôÕâ¶ÎÎÄ×Ö²»ÒªÐ޸ġ£\r\n\\r
37         Ï£ÍûÎÒÄÜΪÖйúµÄÈí¼þÐÐÒµ¾¡Ò»·Ý±¡Á¦£¡\r\n\\r
38                         ¡¾¿ª·¢ÈÕÆÚ¡¿\r\n\\r
39         2008-11-23 3:54\r\n")\r
40 \r
41 #include <afxsock.h>\r
42 \r
43 #if !defined(AFX_HwSMTP_H__633A52B7_1CBE_41D7_BDA3_188D98D692AF__INCLUDED_)\r
44 #define AFX_HwSMTP_H__633A52B7_1CBE_41D7_BDA3_188D98D692AF__INCLUDED_\r
45 \r
46 #if _MSC_VER > 1000\r
47 #pragma once\r
48 #endif // _MSC_VER > 1000\r
49 \r
50 class CHwSMTP  \r
51 {\r
52 public:\r
53         CString GetLastErrorText();\r
54         BOOL SendEmail (\r
55                 LPCTSTR lpszSmtpSrvHost,\r
56                 LPCTSTR lpszUserName,\r
57                 LPCTSTR lpszPasswd,\r
58                 BOOL bMustAuth,\r
59                 LPCTSTR lpszAddrFrom,\r
60                 LPCTSTR lpszAddrTo,\r
61                 LPCTSTR lpszSenderName,\r
62                 LPCTSTR lpszReceiverName,\r
63                 LPCTSTR lpszSubject,\r
64                 LPCTSTR lpszBody,\r
65                 LPCTSTR lpszCharSet,                                            // ×Ö·û¼¯ÀàÐÍ£¬ÀýÈ磺·±ÌåÖÐÎÄÕâÀïÓ¦ÊäÈë"big5"£¬¼òÌåÖÐÎÄʱÊäÈë"gb2312"\r
66                 CStringArray *pStrAryAttach=NULL,\r
67                 CStringArray *pStrAryCC=NULL,\r
68                 UINT nSmtpSrvPort=25\r
69                 );\r
70         CHwSMTP();\r
71         virtual ~CHwSMTP();\r
72 \r
73 private:\r
74         BOOL SendSubject();\r
75         CStringArray m_StrAryCC;\r
76         BOOL SendHead();\r
77         BOOL auth();\r
78         BOOL SendEmail();\r
79         BOOL Send ( LPCTSTR lpszData, ... );\r
80         BOOL GetResponse( LPCTSTR lpszVerifyCode, int *pnCode=NULL );\r
81         BOOL m_bConnected;\r
82         CSocket m_SendSock;\r
83         CStringArray m_StrAryAttach;\r
84         CString m_csSmtpSrvHost;\r
85         CString m_csUserName;\r
86         CString m_csPasswd;\r
87         CString m_csAddrFrom;\r
88         CString m_csAddrTo;\r
89         CString m_csSenderName;\r
90         CString m_csReceiverName;\r
91         CString m_csSubject;\r
92         CString m_csBody;\r
93 private:\r
94         BOOL m_bMustAuth;\r
95         UINT m_nSmtpSrvPort;\r
96         CString m_csCharSet;\r
97 \r
98         CString m_csLastError;\r
99         BOOL SendOnAttach(LPCTSTR lpszFileName);\r
100         BOOL SendAttach();\r
101         BOOL SendBody();\r
102         CString m_csMIMEContentType;\r
103         CString m_csPartBoundary;\r
104         CString m_csNoMIMEText;\r
105 \r
106 };\r
107 \r
108 BOOL SendEmail (\r
109                                   BOOL bViaThreadSend,                                          // FALSE - Ö±½Ó·¢ËÍ£¬ TRUE - ÔÚÏß³ÌÖз¢ËÍ£¬·µ»ØÏ߳̾ä±ú\r
110                                   LPCTSTR lpszSmtpSrvHost,                                      // SMTP ·þÎñÆ÷£¬È磺smtp.21cn.com\r
111                                   LPCTSTR lpszUserName,                                         // µÇ¼·þÎñÆ÷ÑéÖ¤Éí·ÝµÄÓû§Ãû\r
112                                   LPCTSTR lpszPasswd,                                           // µÇ¼·þÎñÆ÷ÑéÖ¤Éí·ÝµÄÃÜÂë\r
113                                   BOOL bMustAuth,                                                       // SMTP ·þÎñÆ÷ÐèÒªÉí·ÝÑéÖ¤\r
114                                   LPCTSTR lpszAddrFrom,                                         // ·¢ËÍÕß E-Mail µØÖ·\r
115                                   LPCTSTR lpszAddrTo,                                           // ½ÓÊÕÕߵĠE-Mail µØÖ·\r
116                                   LPCTSTR lpszSenderName,                                       // ·¢ËÍÕßµÄÃû×Ö£¬ÀýÈ磺лºìΰ\r
117                                   LPCTSTR lpszReceiverName,                                     // ½ÓÊÕÕßµÄÃû×Ö£¬ÀýÈ磺ÕÅ·É\r
118                                   LPCTSTR lpszSubject,                                          // ÓʼþÖ÷Ìâ\r
119                                   LPCTSTR lpszBody,                                                     // ÓʼþÄÚÈÝ\r
120                                   LPCTSTR lpszCharSet=NULL,                                     // ×Ö·û¼¯ÀàÐÍ£¬ÀýÈ磺·±ÌåÖÐÎÄÕâÀïÓ¦ÊäÈë"big5"£¬¼òÌåÖÐÎÄʱÊäÈë"gb2312"\r
121                                   CStringArray *pStrAryAttach=NULL,                     // ¸½¼þÎļþ·¾¶£¬¿ÉÒÔ¶à¸ö\r
122                                   CStringArray *pStrAryCC=NULL,                         // ³­ËÍ E-Mail µØÖ·£¬¿ÉÒÔ¶à¸ö\r
123                                   UINT nSmtpSrvPort=25                                          // SMTP ·þÎñÆ÷µÄ TCP ¶Ë¿ÚºÅ\r
124                                   );\r
125 void EndOfSMTP ();\r
126 \r
127 #endif // !defined(AFX_HwSMTP_H__633A52B7_1CBE_41D7_BDA3_188D98D692AF__INCLUDED_)\r