📄 smtpdoc.cpp
字号:
// smtpDoc.cpp : implementation of the CSmtpDoc class
//
#include "stdafx.h"
#include "smtp.h"
#include "smtpDoc.h"
#include "CSmtp.h"
#include "SmtpSetupDlg.h"
#include "AttachDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSmtpDoc
IMPLEMENT_DYNCREATE(CSmtpDoc, CDocument)
BEGIN_MESSAGE_MAP(CSmtpDoc, CDocument)
//{{AFX_MSG_MAP(CSmtpDoc)
ON_COMMAND(ID_PREFERENCES_SEND, OnPreferencesSend)
ON_COMMAND(ID_PREFERENCES_SETUP, OnPreferencesSetup)
ON_COMMAND(ID_PREFERENCES_ATTACH, OnPreferencesAttach)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSmtpDoc construction/destruction
CSmtpDoc::CSmtpDoc()
{
// TODO: add one-time construction code here
m_SmtpServer = AfxGetApp() -> GetProfileString(_T("SETUP"), _T("SMTPSERVER"), _T("public.sta.net.cn"));
m_From = AfxGetApp() -> GetProfileString(_T("SETUP"), _T("FROM"), _T("jognsa@usa.net"));
m_MailTo = AfxGetApp() -> GetProfileString(_T("SETUP"), _T("TO"), _T("jognsa@usa.net"));
m_Subject = AfxGetApp() -> GetProfileString(_T("SETUP"), _T("SUBJECT"), _T("MailEx! 测试"));
}
CSmtpDoc::~CSmtpDoc()
{
}
BOOL CSmtpDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
((CEditView*)m_viewList.GetHead())->SetWindowText(NULL);
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CSmtpDoc serialization
void CSmtpDoc::Serialize(CArchive& ar)
{
// CEditView contains an edit control which handles all serialization
((CEditView*) m_viewList.GetHead())->SerializeRaw(ar);
}
/////////////////////////////////////////////////////////////////////////////
// CSmtpDoc diagnostics
#ifdef _DEBUG
void CSmtpDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CSmtpDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSmtpDoc commands
void CSmtpDoc::OnPreferencesSend()
{
// TODO: Add your command handler code here
POSITION pos = GetFirstViewPosition();
CEditView* p_View = (CEditView*) GetNextView(pos);
CEdit& m_Ctrl = p_View -> GetEditCtrl();
CSmtp smtp("");
CMIMEMessage msg;
smtp.SetServerProperties(m_SmtpServer);
msg.m_sFrom = _T(m_From);
msg.AddMultipleRecipients(m_MailTo);
msg.m_sSubject = m_Subject;
m_Ctrl.GetWindowText(msg.m_sBody);
for(int lp = 0; lp <= m_Files.GetUpperBound(); lp++) {
msg.AddMIMEPart(m_Files[lp]);
}
if(!smtp.Connect()) {
AfxMessageBox(smtp.GetLastError());
return ;
}
if(!smtp.SendMessage(&msg)) {
AfxMessageBox(smtp.GetLastError());
smtp.Disconnect();
return ;
}
smtp.Disconnect();
m_Files.RemoveAll();
AfxMessageBox(_T("Message sent successfully"));
}
void CSmtpDoc::OnPreferencesSetup()
{
// TODO: Add your command handler code here
SmtpSetupDlg dlg;
if (dlg.DoModal() == IDOK) {
m_SmtpServer = dlg.m_SmtpServer;
m_From = dlg.m_From;
m_MailTo = dlg.m_MailTo;
m_Subject = dlg.m_Subject;
AfxGetApp() -> WriteProfileString(_T("SETUP"), _T("SMTPSERVER"), m_SmtpServer);
AfxGetApp() -> WriteProfileString(_T("SETUP"), _T("FROM"), m_From);
AfxGetApp() -> WriteProfileString(_T("SETUP"), _T("TO"), m_MailTo);
AfxGetApp() -> WriteProfileString(_T("SETUP"), _T("SUBJECT"), m_Subject);
}
}
void CSmtpDoc::OnPreferencesAttach()
{
// TODO: Add your command handler code here
AttachDlg dlg;
if (dlg.DoModal() == IDOK) {
m_Files.RemoveAll();
m_Files.Append(dlg.m_Files);
}
}
void CSmtpDoc::DeleteContents()
{
// TODO: Add your specialized code here and/or call the base class
m_Files.RemoveAll();
CDocument::DeleteContents();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -