SMTPEMailDlg.cpp
资源名称:smtpemail.zip [点击查看]
上传用户:hebinsheng
上传日期:2015-04-30
资源大小:25k
文件大小:9k
源码类别:
ICQ弱点检测代码
开发平台:
Visual C++
- // SMTPEMailDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "SMTPEMail.h"
- #include "SMTPEMailDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- CString m_strEditHelp;
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- virtual BOOL OnInitDialog();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- m_strEditHelp = _T("");
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- DDX_Text(pDX, IDC_EDIT_HELP, m_strEditHelp);
- //}}AFX_DATA_MAP
- }
- BOOL CAboutDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: Add extra initialization here
- m_strEditHelp=
- "相关帮助信息:"
- CRLF
- CRLF
- " 一、 发送邮件服务器和发信人信箱有密切关系,假如你的信箱为loop@sohu.com,则发送邮件服务器一般为:smtp.sohu.com,当然这也不是绝对的,你可以到你的邮件相关网站查询。"
- CRLF
- CRLF
- " 二、 发信信箱格式比较灵活,如下三种格式均为合法的:1 在你的E-Mail首尾加小于大于符号:<loomman@sina.com> 2 直接填写你的E-Mail:loomman@sina.com 3 仅仅填写你的E-Mail帐号:loomman"
- CRLF
- CRLF
- " 三、 接受信箱可以为多个,中间用分号;隔开,例如:Pookie<pookie@sina.com.cn>;snuggles<snuggles@sohu.com>;<loomman@hotmail.com> 某些信箱前面的部分字符串是收信人名称,例如上面的Pookie可以省略不写,例如下面一行和上面一行是等价的,它们都是可以接受的信箱输入格式。<pookie@sina.com.cn>;<snuggles@sohu.com>;<loomman@hotmail.com>"
- CRLF
- CRLF
- " 四、 邮件主题,当然就是邮件的标题了,你可以随意输入或者从下拉列表中选择自己喜爱的标题。"
- CRLF
- CRLF
- " 五、 为了方便大家使用,针对每个空白我都做了一些选项,这样你可以直接从下拉框中选择你需要的,节省时间。"
- CRLF
- CRLF
- " 六、 最后不得不提一下,由于当今好多发送邮件服务器都要求身份验证,也就是需要提供的你的信箱密码,鉴于技术问题,这类信箱本程序暂时不支持。"
- CRLF
- CRLF
- " 一剑"
- CRLF
- " 2003年3月30日"
- CRLF
- ;
- UpdateData(FALSE); // Update the Dialog
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSMTPEMailDlg dialog
- CSMTPEMailDlg::CSMTPEMailDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CSMTPEMailDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CSMTPEMailDlg)
- m_strComboFrom = _T("");
- m_strComboServer = _T("");
- m_strComboSubject = _T("");
- m_strComboTo = _T("");
- m_strEditBody = _T("");
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CSMTPEMailDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSMTPEMailDlg)
- DDX_Control(pDX, IDC_COMBO_TO, m_ctrlComboTo);
- DDX_Control(pDX, IDC_COMBO_SUBJECT, m_ctrlComboSubject);
- DDX_Control(pDX, IDC_COMBO_SERVER, m_ctrlComboServer);
- DDX_Control(pDX, IDC_COMBO_FROM, m_ctrlComboFrom);
- DDX_CBString(pDX, IDC_COMBO_FROM, m_strComboFrom);
- DDX_CBString(pDX, IDC_COMBO_SERVER, m_strComboServer);
- DDX_CBString(pDX, IDC_COMBO_SUBJECT, m_strComboSubject);
- DDX_CBString(pDX, IDC_COMBO_TO, m_strComboTo);
- DDX_Text(pDX, IDC_EDIT_BODY, m_strEditBody);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CSMTPEMailDlg, CDialog)
- //{{AFX_MSG_MAP(CSMTPEMailDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_ABOUT, OnAbout)
- ON_BN_CLICKED(IDSEND, OnSend)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSMTPEMailDlg message handlers
- BOOL CSMTPEMailDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
- // TODO: Add extra initialization here
- m_ctrlComboServer.InsertString(0,"mail.czvc.com");
- m_ctrlComboServer.InsertString(1,"smtp.sina.com.cn");
- m_ctrlComboServer.InsertString(2,"smtp.163.com");
- m_ctrlComboServer.InsertString(3,"smtp.sohu.com");
- m_ctrlComboServer.InsertString(4,"smtp.163.net");
- m_ctrlComboServer.InsertString(5,"smtp.263.net");
- m_ctrlComboServer.InsertString(6,"smtp.yahoo.com.cn");
- m_ctrlComboServer.InsertString(7,"smtp.21cn.com");
- m_ctrlComboServer.InsertString(8,"mail.fm365.com");
- m_ctrlComboServer.InsertString(9,"smtp.elong.com");
- m_ctrlComboServer.InsertString(10,"smtp.etang.com");
- m_ctrlComboServer.InsertString(11,"smtp.yahoo.com");
- //发送人信箱
- m_ctrlComboFrom.InsertString(0,"<info@czvc.com>");
- m_ctrlComboFrom.InsertString(1,"<loomman@sina.com>");
- //接受人信箱,当然您可以在此添加更多的接受信箱:)
- m_ctrlComboTo.InsertString(0,"<info@czvc.com>;<loomman@hotmail.com>");
- m_ctrlComboSubject.InsertString(0,"嗨,你好!");
- m_ctrlComboSubject.InsertString(1,"好久不见,近来可好?");
- m_ctrlComboSubject.InsertString(2,"久违了,老兄!");
- m_ctrlComboSubject.InsertString(3,"新年快乐!");
- m_ctrlComboSubject.InsertString(4,"小妹妹你好!");
- m_ctrlComboSubject.InsertString(5,"朋友,你现在还好吗?");
- m_ctrlComboSubject.InsertString(6,"你好,可以和你做个朋友吗?");
- m_ctrlComboSubject.InsertString(7,"我爱你!");
- m_ctrlComboSubject.InsertString(8,"亲爱的,我想你!");
- m_ctrlComboSubject.InsertString(9,"可以认识你吗?");
- m_ctrlComboSubject.InsertString(10,"Are you girl?");
- m_ctrlComboSubject.InsertString(11,"Hi, nice to see you!");
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CSMTPEMailDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CSMTPEMailDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CSMTPEMailDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CSMTPEMailDlg::OnOK()
- {
- }
- void CSMTPEMailDlg::OnAbout()
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- void CSMTPEMailDlg::OnSend()
- {
- UpdateData( TRUE );
- CSMTP smtp( m_strComboServer );
- CMailMessage msg;
- msg.m_sFrom = m_strComboFrom;
- msg.AddMultipleRecipients( m_strComboTo );
- msg.m_sSubject = m_strComboSubject;
- msg.m_sBody = m_strEditBody;
- if( !smtp.Connect() )
- {
- AfxMessageBox( smtp.GetLastError() );
- return;
- }
- if( !smtp.SendMessage( &msg ) )
- {
- AfxMessageBox( smtp.GetLastError() );
- return;
- }
- if( !smtp.Disconnect() )
- {
- AfxMessageBox( smtp.GetLastError() );
- return;
- }
- AfxMessageBox( _T( "邮件发送成功!") );
- //以下几行代码可选
- //m_strComboTo = "";
- //m_strComboSubject = "";
- //m_strEditBody = "";
- //UpdateData( FALSE );
- //m_ctrlComboTo.SetFocus();
- }