策略为王-SMailer.cpp

Published

1.SMailer类的定义

G:\stock\TskingVS2019\src\Client\StkNet\Src\SMailer\SMailer.cpp

 

2.发送接口

G:\stock\TskingVS2019\src\Client\StkNet\Src\AfxCore.cpp

STKNET_API	BOOL AfxSendMail(LPCTSTR lpszSenderName, LPCTSTR lpszSenderAddress,
							 LPCTSTR lpszReceiverName, LPCTSTR lpszReceiverAddress,
							 LPCTSTR lpszSubject, LPCTSTR lpszContent, CString & strErrorMsg )
{
	CString sContent = lpszContent;
	CString sContentHTML = "<HTML><BODY><PRE>" + sContent + "</PRE></BODY></HTML>";
	
	SMailer::TextPlainContent * content1 = new SMailer::TextPlainContent( LPCTSTR(sContent) );
	SMailer::TextHtmlContent  * content2 = new SMailer::TextHtmlContent( LPCTSTR(sContentHTML) );

	SMailer::MailInfo info;
	info.setSenderName( lpszSenderName );
	info.setSenderAddress( lpszSenderAddress );
	info.addReceiver( lpszReceiverName, lpszReceiverAddress );
	info.setPriority(SMailer::Priority::normal);
	info.setSubject( lpszSubject );
	info.addMimeContent( content1 );
	info.addMimeContent( content2 );

	//发送邮件用户名,密码设置 by freeman
	SMailer::MailSender sender( (LPCTSTR)AfxGetProfile().GetEvaluateSMTPServer(),
								(LPCTSTR)AfxGetProfile().GetEvaluateSMTPUser(),
								(LPCTSTR)AfxGetProfile().GetEvaluateSMTPPasswd() );
	sender.setMail(&SMailer::MailWrapper(&info));
	BOOL success = sender.sendMail();
	if( !success )
		strErrorMsg += sender.getErrMessage();
	if( content1 )	{	delete content1;	content1 = NULL;	}
	if( content2 )	{	delete content2;	content2 = NULL;	}
	return success;
}

 

相关信息如下:

G:\stock\TskingVS2019\src\Client\StkLib\Src\Profile.cpp

// 域名加密方法,时间返回的是ninebulls.com  by freeman
CSPString CStProfile::GetMainServerDomain()
{
	CSPString strResult;

	char szMainServerDomainFmt[] = "%sin%su%sls%sco%s";
								//   ninebulls.com by freeman
								//   ^   ^^ ^   ^   ^
	strResult.Format( szMainServerDomainFmt, "n", "eb", "l", ".", "m" ); 
	strResult = "tsking.cn";
	strResult = "ninebulls.com";
	

	return strResult;
}
//发送邮件地址
CSPString CStProfile::GetEvaluateEmail( )
{
	CSPString	strResult;
	strResult.Format( "evaluate@%s", (LPCTSTR)GetMainServerDomain() );//[email protected] by freeman
	return strResult;
}

//发送邮件服务器
CSPString CStProfile::GetEvaluateSMTPServer( )
{
	CSPString	strResult;
	strResult.Format( "mail.%s", (LPCTSTR)GetMainServerDomain() ); //mail.ninebulls.com by freeman
	return strResult;
}

//发送邮件用户名
CSPString CStProfile::GetEvaluateSMTPUser( )
{
	CSPString	strResult;
	strResult.Format( "evasend@%s", (LPCTSTR)GetMainServerDomain() );//[email protected] by freeman
	return strResult;
}

//发送邮件密码
CSPString CStProfile::GetEvaluateSMTPPasswd( ) //evasend by freeman
{
	return "evasend";
}

3.发送邮件

G:\stock\TskingVS2019\src\Client\StkNet\Src\AfxCore.cpp

STKNET_API	BOOL AfxApplyForEvaluation(LPCTSTR lpszUserName, LPCTSTR lpszDistrict,
									   LPCTSTR lpszClass, LPCTSTR lpszEmail,
									   CString & strErrorMsg )
{
	if( NULL == lpszUserName || NULL == lpszDistrict || NULL == lpszClass || NULL == lpszEmail )
		return FALSE;
	if( strlen(lpszUserName) <= 0 || strlen(lpszDistrict) <= 0 || strlen(lpszClass) <= 0 || strlen(lpszEmail) <= 0 )
		return FALSE;

	CString	sSubject = AfxModuleLoadString( IDS_APPLYFOREVA_SUBJECT );

	CString sContent;
#ifdef CLKLAN_ENGLISH_US
	sContent	+=	"\r\nVersion:Ninebulls310-20060325";
#else
	sContent	+=	"\r\nVersion:CLKing310-20060325";
#endif
	sContent	+=	"\r\nUser:";
	sContent	+=	lpszUserName;
	sContent	+=	"\r\n";
	sContent	+=	"District:";
	sContent	+=	lpszDistrict;
	sContent	+=	"\r\n";
	sContent	+=	"Class:";
	sContent	+=	lpszClass;
	sContent	+=	"\r\n";
	sContent	+=	"Email:";
	sContent	+=	lpszEmail;
	sContent	+=	"\r\n";

	CString sEvaCode;
	if( AfxGetEvaluateCode(sEvaCode) )
	{
		sContent	+=	"EvaCode:";
		sContent	+=	sEvaCode;
		sContent	+=	"\r\n";
		if( AfxSendMail( lpszUserName, lpszEmail, "evaluate", (LPCTSTR)AfxGetProfile().GetEvaluateEmail(),
							(LPCTSTR)sSubject, (LPCTSTR)sContent, strErrorMsg ) )
		{
			CString sReplyContent = AfxModuleLoadString( IDS_APPLYFOREVA_REPLYCONTENT );
			sReplyContent += "\r\n\r\n    ";
			sReplyContent += sEvaCode;
			sReplyContent += "\r\n\r\n";
			sReplyContent += AfxModuleLoadString( IDS_APPLYFOREVA_REPLYDESCRIPT );
			return AfxSendMail( "", (LPCTSTR)AfxGetProfile().GetEvaluateEmail(), lpszUserName, lpszEmail,
						(LPCTSTR)("Re:"+sSubject), (LPCTSTR)sReplyContent, strErrorMsg );
		}
	}
	return FALSE;
}