//初始化邮件类
void InitEmail(C01waSendMail* m_globalEmail,String sendermail,String sender,String senderpwd,String srv,int port = 25,bool bSsl = false)
{
m_globalEmail->m_Auth = CPJNSMTPConnection::AuthenticationMethod::AUTH_AUTO;
m_globalEmail->m_bAutoDial = true;
m_globalEmail->m_bSSL = bSsl;
m_globalEmail->m_sUsername = sender.c_str();
m_globalEmail->m_sAddress = sendermail.c_str();
m_globalEmail->m_sPassword = senderpwd.c_str();
m_globalEmail->m_sHost = srv.c_str();
m_globalEmail->m_nPort = port;
m_globalEmail->m_sEncodingFriendly = _T("Chinese Simplified (GB2312)");
m_globalEmail->m_sEncodingCharset = _T("gb2312");
m_globalEmail->m_bMime = 1;
m_globalEmail->m_bHTML = 1;
m_globalEmail->m_Priority = CPJNSMTPMessage::PRIORITY::NormalPriority;
m_globalEmail->m_bDSN = FALSE;
m_globalEmail->m_bDSNSuccess = FALSE;
m_globalEmail->m_bDSNFailure = FALSE;
m_globalEmail->m_bDSNDelay = FALSE;
m_globalEmail->m_bDSNHeaders = FALSE;
m_globalEmail->m_bDNSLookup = FALSE;
}
//发送邮件
void SendEmail(const char* recvemail,const char* subject,const char* body,const char * sCC=NULL,const char * bCC = NULL,const char * attach = NULL)
{
//初始化邮箱
//注意释放内存
C01waSendMail *m_globalEmail = new C01waSendMail;
if(strlen(m_con1.m_eamil)>0&&strlen(m_con1.m_pwd)&&strlen(m_con1.m_smtpsrv)&&m_con1.port>0)
{
char * p = strdup(m_con1.m_eamil);
char * pp = strstr(p,"@");
if(pp>0)
pp[0] = '\0';
InitEmail(m_globalEmail,m_con1.m_eamil,p,m_con1.m_pwd,m_con1.m_smtpsrv,m_con1.port,m_con1.ssl);
free(p);
if(subject>0)
m_globalEmail->m_sSubject.Format("%s",subject);
if(sCC>0)
m_globalEmail->m_sCC.Format("%s",sCC);
if(bCC>0)
m_globalEmail->m_sBCC.Format("%s",bCC);
if(body>0)
m_globalEmail->m_sBody.Format("%s",body);
if(attach>0)
m_globalEmail->m_sFile.Format("%s",attach);
if(recvemail>0)
m_globalEmail->m_sTo.Format("%s",recvemail);
m_globalEmail->SendEmail();
}
}
2021-08-23 17:01:37
1.33MB
smtp
1