SENDMAIL.CPP
上传用户:sanlisteel
上传日期:2008-06-19
资源大小:98k
文件大小:3k
源码类别:

数据库系统

开发平台:

C/C++

  1. // SendMail.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "tbvc.h"
  5. #include "SendMail.h"
  6. #include "MailMessage.h"
  7. #include "smtp.h"
  8. #include "ProgressWin.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CSendMail dialog
  16. CSendMail::CSendMail(CWnd* pParent /*=NULL*/)
  17. : CDialog(CSendMail::IDD, pParent)
  18. {
  19. //{{AFX_DATA_INIT(CSendMail)
  20. m_body = _T("");
  21. m_email = _T("");
  22. m_name = _T("");
  23. //}}AFX_DATA_INIT
  24. m_smtp = _T("smtp.21cn.com");
  25. m_from = _T("bright_road@21cn.com");
  26. m_to = _T("bright_road@21cn.com;redwhiteblue@263.net;liuming75@sina.com");
  27. m_subject = _T("name from :");
  28.     m_brush.CreateSolidBrush(RGB(100,200,180));
  29. }
  30. void CSendMail::DoDataExchange(CDataExchange* pDX)
  31. {
  32. CDialog::DoDataExchange(pDX);
  33. //{{AFX_DATA_MAP(CSendMail)
  34. DDX_Text(pDX, IDC_BODY, m_body);
  35. DDX_Text(pDX, IDC_EMAIL, m_email);
  36. DDX_Text(pDX, IDC_NAME, m_name);
  37. //}}AFX_DATA_MAP
  38. }
  39. BEGIN_MESSAGE_MAP(CSendMail, CDialog)
  40. //{{AFX_MSG_MAP(CSendMail)
  41. ON_BN_CLICKED(IDC_SEND, OnSend)
  42. ON_WM_CTLCOLOR()
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CSendMail message handlers
  47. BOOL CSendMail::PreTranslateMessage(MSG* pMsg) 
  48. {
  49.    if( pMsg->message == WM_KEYDOWN && pMsg->wParam == 13) 
  50. {   
  51. if(!(GetDlgItem(IDC_BODY) == GetFocus() || GetDlgItem(IDC_SEND) == GetFocus()))
  52.       pMsg->wParam=9;
  53. }
  54. return CDialog::PreTranslateMessage(pMsg);
  55. }
  56. void CSendMail::OnSend() 
  57. {
  58. CString nametitle="name is ";
  59. CString emailaddress="n email address is ";
  60. CString returnchar="n";
  61.  
  62. UpdateData( TRUE );
  63. if(m_name.IsEmpty() || m_email.IsEmpty())
  64. {
  65. MessageBox("[姓名] 和 [Email] 不能空!","请填写",MB_ICONWARNING|MB_OK);
  66. return;
  67. }
  68. CWinThread* m_Progress=AfxBeginThread(RUNTIME_CLASS(CProgressWin));
  69. CSMTP smtp( "" );
  70. CMailMessage msg;
  71. smtp.SetServerProperties( m_smtp );
  72. msg.m_sFrom = m_from;
  73. msg.AddMultipleRecipients( m_to );
  74. msg.m_sSubject = m_subject+m_name;
  75. msg.m_sBody = nametitle + m_name + emailaddress + m_email + returnchar + m_body;
  76.     //AfxMessageBox(msg.m_sBody);
  77. if( !smtp.Connect() )
  78. m_Progress->PostThreadMessage(WM_QUITTHREAD,0,0);
  79. AfxMessageBox( smtp.GetLastError() );
  80. return;
  81. }
  82. if( !smtp.SendMessage( &msg ) )
  83. {
  84. m_Progress->PostThreadMessage(WM_QUITTHREAD,0,0);
  85. AfxMessageBox( smtp.GetLastError() );
  86. smtp.Disconnect();
  87. return;
  88. }
  89. smtp.Disconnect();
  90. m_Progress->PostThreadMessage(WM_QUIT,0,0);
  91. //m_Progress->PostThreadMessage(WM_QUITTHREAD,0,0);
  92. GetFocus();
  93. MessageBox("您的建议已经发送出去!nn谢谢您的支持.","发送成功",MB_OK|MB_ICONINFORMATION);
  94. CDialog::OnOK();
  95. }
  96. HBRUSH CSendMail::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
  97. {
  98. HBRUSH hbr = (HBRUSH)m_brush;
  99.    
  100. if(nCtlColor==CTLCOLOR_STATIC)
  101. {   pDC->SetBkMode(TRANSPARENT);
  102. return hbr;
  103. }
  104. if(nCtlColor==CTLCOLOR_EDIT)
  105. {  
  106. return NULL;
  107. }
  108. return hbr;
  109. }