int CSmtpClient::SendEmail(CEmailMessage* msg) { m_scn->SetProgress(_T("Start sending email"), 0, false); std::map<WORD, CString> host_list; // Check whether to use proxy server or to resolve SMTP server // address from MX record of domain. if(!m_sServer.IsEmpty()) { // Use proxy server host_list[0] = m_sServer; } else { // Resolve domain name(s) from DNS record int res = ResolveSmtpServerName(msg->GetRecipientAddress(0), host_list); if(res!=0) { m_scn->SetProgress(_T("Error querying DNS record."), 100, false); return 1; } } // For each resolved domain name of SMTP server, try to send E-mail to the specified domain. std::map<WORD, CString>::iterator it; for(it=host_list.begin(); it!=host_list.end(); it++) { // Check if operation cancelled by user if(m_scn->IsCancelled()) return 2; // Send E-mail to current SMTP server int res = SendEmailToRecipient(it->second, msg); if(res==0) { // Succeeded m_scn->SetProgress(_T("Finished OK."), 100, false); return 0; } if(res==2) { // Failure m_scn->SetProgress(_T("Critical error detected."), 100, false); return 2; } } // Failed to send E-mail m_scn->SetProgress(_T("Error sending email."), 100, false); return 1; }
int CSmtpClient::_SendEmail(CEmailMessage* msg, AssyncNotification* scn) { scn->SetProgress(_T("Start sending email"), 0, false); std::map<WORD, CString> host_list; if(!m_sProxyServer.IsEmpty()) { host_list[0] = m_sProxyServer; } else { int res = GetSmtpServerName(msg, scn, host_list); if(res!=0) { scn->SetProgress(_T("Error querying DNS record."), 100, false); return 1; } } std::map<WORD, CString>::iterator it; for(it=host_list.begin(); it!=host_list.end(); it++) { if(scn->IsCancelled()) return 2; int res = SendEmailToRecipient(it->second, msg, scn); if(res==0) { scn->SetProgress(_T("Finished OK."), 100, false); return 0; } if(res==2) { scn->SetProgress(_T("Critical error detected."), 100, false); return 2; } } scn->SetProgress(_T("Error sending email."), 100, false); return 1; }