SENDMAIL.CPP
上传用户:sanlisteel
上传日期:2008-06-19
资源大小:98k
文件大小:3k
- // SendMail.cpp : implementation file
- //
- #include "stdafx.h"
- #include "tbvc.h"
- #include "SendMail.h"
- #include "MailMessage.h"
- #include "smtp.h"
- #include "ProgressWin.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CSendMail dialog
- CSendMail::CSendMail(CWnd* pParent /*=NULL*/)
- : CDialog(CSendMail::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CSendMail)
- m_body = _T("");
- m_email = _T("");
- m_name = _T("");
- //}}AFX_DATA_INIT
- m_smtp = _T("smtp.21cn.com");
- m_from = _T("bright_road@21cn.com");
- m_to = _T("bright_road@21cn.com;redwhiteblue@263.net;liuming75@sina.com");
- m_subject = _T("name from :");
- m_brush.CreateSolidBrush(RGB(100,200,180));
- }
- void CSendMail::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSendMail)
- DDX_Text(pDX, IDC_BODY, m_body);
- DDX_Text(pDX, IDC_EMAIL, m_email);
- DDX_Text(pDX, IDC_NAME, m_name);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CSendMail, CDialog)
- //{{AFX_MSG_MAP(CSendMail)
- ON_BN_CLICKED(IDC_SEND, OnSend)
- ON_WM_CTLCOLOR()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSendMail message handlers
- BOOL CSendMail::PreTranslateMessage(MSG* pMsg)
- {
- if( pMsg->message == WM_KEYDOWN && pMsg->wParam == 13)
- {
- if(!(GetDlgItem(IDC_BODY) == GetFocus() || GetDlgItem(IDC_SEND) == GetFocus()))
- pMsg->wParam=9;
- }
- return CDialog::PreTranslateMessage(pMsg);
- }
- void CSendMail::OnSend()
- {
- CString nametitle="name is ";
- CString emailaddress="n email address is ";
- CString returnchar="n";
-
- UpdateData( TRUE );
- if(m_name.IsEmpty() || m_email.IsEmpty())
- {
- MessageBox("[姓名] 和 [Email] 不能空!","请填写",MB_ICONWARNING|MB_OK);
- return;
- }
- CWinThread* m_Progress=AfxBeginThread(RUNTIME_CLASS(CProgressWin));
- CSMTP smtp( "" );
- CMailMessage msg;
-
- smtp.SetServerProperties( m_smtp );
- msg.m_sFrom = m_from;
- msg.AddMultipleRecipients( m_to );
- msg.m_sSubject = m_subject+m_name;
- msg.m_sBody = nametitle + m_name + emailaddress + m_email + returnchar + m_body;
- //AfxMessageBox(msg.m_sBody);
- if( !smtp.Connect() )
- {
- m_Progress->PostThreadMessage(WM_QUITTHREAD,0,0);
- AfxMessageBox( smtp.GetLastError() );
-
- return;
- }
- if( !smtp.SendMessage( &msg ) )
- {
- m_Progress->PostThreadMessage(WM_QUITTHREAD,0,0);
- AfxMessageBox( smtp.GetLastError() );
- smtp.Disconnect();
-
- return;
- }
- smtp.Disconnect();
- m_Progress->PostThreadMessage(WM_QUIT,0,0);
- //m_Progress->PostThreadMessage(WM_QUITTHREAD,0,0);
- GetFocus();
- MessageBox("您的建议已经发送出去!nn谢谢您的支持.","发送成功",MB_OK|MB_ICONINFORMATION);
-
- CDialog::OnOK();
- }
- HBRUSH CSendMail::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr = (HBRUSH)m_brush;
-
- if(nCtlColor==CTLCOLOR_STATIC)
- { pDC->SetBkMode(TRANSPARENT);
- return hbr;
- }
- if(nCtlColor==CTLCOLOR_EDIT)
- {
- return NULL;
- }
- return hbr;
- }