📄 main.cpp
字号:
#include "stdafx.h"
#include "smtp.h"
class CApp : public CWinApp
{
protected:
virtual BOOL InitInstance();
};
CApp theApp;
BOOL CApp::InitInstance()
{
//initialise sockets
if (!AfxSocketInit())
{
TRACE(_T("Failed to initialise the Winsock stack\n"));
return FALSE;
}
//Test the multiple recipients code
CSMTPMessage testm;
testm.AddMultipleRecipients(_T(" PJ Naughter < pjn@indigo.ie > , My Boss <someboss@company.com> ; Joe <joe@somecompany.com>"), CSMTPMessage::TO);
testm.AddMultipleRecipients(_T("PJ Naughter <pj.naughter@softech-telecom.com> ,Joe <joe@company.com>"), CSMTPMessage::CC);
testm.AddMultipleRecipients(_T("PJ Naughter < pjn@indigo.ie > , My Boss <someboss@company.com> ; Joe <joe@ms.com>"), CSMTPMessage::BCC);
//Create the SMTP connection
CSMTPConnection smtp;
//Connect to the server
if (!smtp.Connect(_T("mail.indigo.ie")))
{
CString sResponse = smtp.GetLastCommandResponse();
TRACE(_T("Failed to connect to SMTP server\n"));
return FALSE;
}
//Create a test message
CSMTPMessage m;
CSMTPAddress From(_T("PJ Naughter"), _T("pjn@indigo.ie")); //Change these values to your settings
m.m_From = From;
CSMTPAddress To(_T("PJ Naughter"), _T("pjn@indigo.ie")); //Change these values to your settings
m.AddRecipient(To, CSMTPMessage::TO);
CSMTPAddress CC(_T("PJ Naughter"), _T("pjn@indigo.ie")); //Change these values to your settings
m.AddRecipient(CC, CSMTPMessage::CC);
CSMTPAddress BCC(_T("PJ Naughter"), _T("pjn@indigo.ie")); //Change these values to your settings
m.AddRecipient(BCC, CSMTPMessage::BCC);
m.m_sSubject = _T("Test Message from CSMTP class - Please Ignore");
m.AddBody(_T("The CSMTPConnection classes allows\r\n\r\nyou to send SMTP messages from MFC code"));
//Testing Reply To support
m.m_ReplyTo = CSMTPAddress(_T("Another PJ"), _T("pj.naughter@softech-telecom.com"));
//Testing attachment support
CSMTPAttachment attachment;
attachment.Attach(_T("C:\\AUTOEXEC.BAT"));
m.AddAttachment(&attachment);
//Sent the message
if (!smtp.SendMessage(m))
{
CString sResponse = smtp.GetLastCommandResponse();
TRACE(_T("Failed to send the SMTP message\n"));
return FALSE;
}
//Disconnect from the server
smtp.Disconnect();
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -