if (NS_FAILED(rv))
if (NS_FAILED(rv) || !mailSession)
main(int argc, char *argv[]) {   nsIMsgCompFields    *pMsgCompFields;  nsIMsgSend          *pMsgSend;  nsresult            rv = NS_OK;  // Before anything, do some sanity checking :-)  if (argc < 4)  {    printf("Usage: %s <recipients> <web_page_url> <email_subject>\n", argv[0]);    exit(0);  }  SetupRegistry();  // Create the Event Queue for this thread...	NS_WITH_SERVICE(nsIEventQueueService, pEventQService, kEventQueueServiceCID, &rv); 	if (NS_FAILED(rv))   {    printf("Failed to get event queue\n");    return rv;  }  rv = pEventQService->CreateThreadEventQueue();	if (NS_FAILED(rv))   {    printf("Failed to create event queue\n");    return rv;  }	// make sure prefs get initialized and loaded..	NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv);   if (NS_FAILED(rv) || (!prefs))   {    printf("Failed on prefs service!\n");    exit(rv);  }  if (NS_FAILED(prefs->ReadUserPrefs()))  {    printf("Failed on reading user prefs!\n");    exit(rv);  }  NS_WITH_SERVICE(nsIMsgMailSession, mailSession, kCMsgMailSessionCID, &rv);  if (NS_FAILED(rv))   {    printf("Failure on Mail Session Init!\n");    return rv;  }    rv = nsComponentManager::CreateInstance(kMsgSendCID, NULL, nsIMsgSend::GetIID(), (void **) &pMsgSend);   if (NS_SUCCEEDED(rv) && pMsgSend)   {     printf("We succesfully obtained a nsIMsgSend interface....\n");        rv = nsComponentManager::CreateInstance(kMsgCompFieldsCID, NULL, nsIMsgCompFields::GetIID(),                                              (void **) &pMsgCompFields);     if (NS_SUCCEEDED(rv) && pMsgCompFields)     if (rv == NS_OK && pMsgCompFields)    {       nsIMsgIdentity  *ident = GetHackIdentity();      char            *email = nsnull;      if (ident)        ident->GetEmail(&email);      if (!email)        email = "rhp@netscape.com";      pMsgCompFields->SetFrom(email, NULL);      pMsgCompFields->SetTo(argv[1], NULL);      pMsgCompFields->SetSubject(argv[3], NULL);      pMsgCompFields->SetBody(argv[2], NULL);      nsIURI    *url;      char      *ptr = argv[2];      while (*ptr)      {        if (*ptr == '\\')          *ptr = '/';        ++ptr;      }      nsMsgNewURL(&url, argv[2]);      if (!url)      {        printf("Error creating new URL object.\n");        return -1;      }      // Create the listener for the send operation...      SendOperationListener *mSendListener = new SendOperationListener();      if (!mSendListener)      {        return NS_ERROR_FAILURE;      }            // set this object for use on completion...      nsIMsgSendListener **tArray = CreateListenerArray(mSendListener);      if (!tArray)      {        printf("Error creating listener array.\n");        return NS_ERROR_FAILURE;      }      pMsgSend->SendWebPage(pMsgCompFields, url, nsMsgDeliverNow, tArray);    }      }#ifdef XP_PC  printf("Sitting in an event processing loop ...Hit Cntl-C to exit...");  while (keepOnRunning)  {    MSG msg;    if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))    {      TranslateMessage(&msg);      DispatchMessage(&msg);    }  }#endif  printf("Releasing the interface now...\n");  if (pMsgSend)    pMsgSend->Release();   if (pMsgCompFields)    pMsgCompFields->Release();   return 0; }