Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB

  1. #include "SMTP.h"
  2. BOOL CSMTP::InitSMTP(){
  3. HRESULT hr = CoInitialize(NULL);
  4. pIMsg = NULL;
  5. // create a SMTP message object. If fails then closeandwait and try next time
  6. HRESULT hrMsg;
  7. hrMsg = pIMsg.CreateInstance(__uuidof(Message));
  8. if(FAILED(hrMsg)) {
  9. AddServiceLog(_T("Error: Failed to create SMTP message object\r\n"));
  10. LogFatalEvent(_T("Failed to create SMTP message object"));
  11. return FALSE;
  12. }
  13. // we have to addref here and call release when we are done with pIMsg
  14. // pIMsg->AddRef();
  15. return TRUE;
  16. }
  17. BOOL CSMTP::SendMail(StructMailParams& stMailParams){
  18. // prepare the mail now
  19. _TCHAR szMailSubject[1024];
  20. _tcscpy(szMailSubject, _T("Multiple KD Failures"));
  21. _TCHAR szMailBody[1024];
  22. _stprintf(szMailBody, _T("KD Failed.\r\nServer: %s\r\nFailures: %ld\r\nInterval %ld\r\nTimestamp: %ld\r\n"),
  23. stMailParams.szServerName, stMailParams.ulFailures,
  24. stMailParams.ulInterval, stMailParams.ulCurrentTimestamp);
  25. pIMsg->From = stMailParams.szFrom;
  26. pIMsg->To = stMailParams.szTo;
  27. pIMsg->Subject = szMailSubject;
  28. pIMsg->TextBody = szMailBody;
  29. HRESULT hrSend;
  30. hrSend = pIMsg->Send();
  31. if ( FAILED(hrSend) ) {
  32. AddServiceLog(_T("Error: Failed to send the message.\r\n"));
  33. LogFatalEvent(_T("Failed to send the message."));
  34. return FALSE;
  35. }
  36. return TRUE;
  37. }
  38. // cleanup the message object
  39. BOOL CSMTP::SMTPCleanup() {
  40. //if (pIMsg != NULL) pIMsg->Release();
  41. CoUninitialize();
  42. return TRUE;
  43. }