if (NS_FAILED(rv))
if (NS_FAILED(rv) || !mailSession)
int main(int argc, char *argv[]) {   nsresult rv = NS_OK;  nsIAppShellService* appShell = nsnull;  nsComponentManager::RegisterComponent(kNetServiceCID, NULL, NULL, NETLIB_DLL, PR_FALSE, PR_FALSE);	nsComponentManager::RegisterComponent(kEventQueueServiceCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);	nsComponentManager::RegisterComponent(kEventQueueCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);	nsComponentManager::RegisterComponent(kPrefCID, nsnull, nsnull, PREF_DLL, PR_TRUE, PR_TRUE);	nsComponentManager::RegisterComponent(kFileLocatorCID,  NULL, NULL, APPSHELL_DLL, PR_FALSE, PR_FALSE);	nsComponentManager::RegisterComponent(kMimeURLUtilsCID,  NULL, NULL, MIME_DLL, PR_FALSE, PR_FALSE);	nsComponentManager::RegisterComponent(kNetSupportDialogCID,  NULL, NULL, APPSHELL_DLL, PR_FALSE, PR_FALSE);	nsComponentManager::RegisterComponent(kAppShellServiceCID,  NULL, NULL, APPSHELL_DLL, PR_FALSE, PR_FALSE);  /*   * Create the Application Shell instance...   */  nsCOMPtr<nsIWebShellWindow> newWindow;  rv = nsServiceManager::GetService(kAppShellServiceCID,                                    kIAppShellServiceIID,                                   (nsISupports**)&appShell);	if (NS_SUCCEEDED(rv))     appShell->CreateTopLevelWindow(nsnull, nsnull, PR_TRUE, getter_AddRefs(newWindow),                nsnull, nsnull, 200, 200);  // 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..	// mscott - this is just a bad bad bad hack right now until prefs	// has the ability to take nsnull as a parameter. Once that happens,	// prefs will do the work of figuring out which prefs file to load...	NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv);     if (NS_FAILED(rv) || (prefs == nsnull)) {        exit(rv);    } if (NS_FAILED(prefs->ReadUserPrefs())) {   printf("Failed on reading user prefs!\n");   exit(-1); }  NS_WITH_SERVICE(nsIMsgMailSession, mailSession, kCMsgMailSessionCID, &rv);  if (NS_FAILED(rv))   {    printf("Failure on Mail Session Init!\n");    return rv;  }    nsCOMPtr<nsIMsgIdentity>  identity = nsnull;    NS_WITH_SERVICE(nsIMsgMailSession, session, kCMsgMailSessionCID, &rv);  if (NS_FAILED(rv))   {    printf("Failure getting Mail Session!\n");    return rv;  }    nsCOMPtr<nsIMsgAccountManager> accountManager;  rv = session->GetAccountManager(getter_AddRefs(accountManager));  if (NS_FAILED(rv))   {    printf("Failure getting account Manager!\n");    return rv;  }    rv = session->GetCurrentIdentity(getter_AddRefs(identity));  if (NS_FAILED(rv))   {    printf("Failure getting Identity!\n");    return rv;  }      nsCOMPtr<nsIMsgSendLater> pMsgSendLater;  rv = nsComponentManager::CreateInstance(kMsgSendLaterCID, NULL, kIMsgSendLaterIID,                                           (void **) getter_AddRefs(pMsgSendLater));   if (NS_SUCCEEDED(rv) && pMsgSendLater)   {     printf("We succesfully obtained a nsIMsgSendLater interface....\n");        pMsgSendLater->SendUnsentMessages(identity, nsnull, nsnull);  }#ifdef XP_PC  printf("Sitting in an event processing loop ...Hit Cntl-C to exit...");  while (1)  {    MSG msg;    if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))    {      TranslateMessage(&msg);      DispatchMessage(&msg);    }  }#endif  return 0; }