vc下基于SMTP协议的发送电子邮件代码
Response_buf=new TCHAR[RESPONSE_BUFFER_SIZE];
if(response_buf==NULL)
{
m_sError=_T("内存不足");
Return FALSE;
}
if(!m_wsSMTPServer.Create())
{
//建立套接字失败
m_sError=_T("无法创建套接字");
delete response_buf;
response_buf=NULL;
return FALSE;
}
If(!m_wsSMTPServer.Connect(GetServerHostName(),GetPort()))
{
m_sError=_T("无法与服务器建立连接!");
m_wsSMTPServer.Close();
delete response_buf;
response_buf=NULL;
return FALSE;
}
If(!get_response(CONNECT_SUCCESS))
{
//接受应答信息失败
m_sError=_T("服务器没有回答!");
m_wsSMTPServer.Close();
delete response_buf;
response_buf=NULL;
return FALSE;
}
Gethostname(local_host,HOSTNAMELENGTH);
//以HELLO命令开始发信
sHello.Format(_T("HELLO %s\r\n"),local_host);
m_wsSMTPServer.Send((LPCTSTR)sHello,sHello.GetLength());
If(!get_response(GENERIC_SUCCESS))
{
//获得应答信息失败
m_wsSMTPServer.Close();