if (NS_FAILED(rv))
if (NS_FAILED(rv) || !mailSession)
int main(int argc, char *argv[]) {   nsIMsgCompFields  *pMsgCompFields;  nsIMsgSend        *pMsgSend;  nsresult          rv = NS_OK;  nsFileSpec        *mailFile = 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);  // 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))   {    printf("Failed to get the 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(kMsgCompFieldsCID, NULL,                                            nsIMsgCompFields::GetIID(), (void **) &pMsgCompFields);     if (rv == NS_OK && pMsgCompFields) {     printf("We succesfully obtained a nsIMsgCompFields interface....\n");    printf("Releasing the interface now...\n");    pMsgCompFields->Release();   }     printf("Creating temp mail file...\n");  mailFile = nsMsgCreateTempFileSpec("mailTest.eml");  if (NS_FAILED(WriteTempMailFile(mailFile)))  {    printf("Failed to create temp mail file!\n");    return 0;  }  rv = nsComponentManager::CreateInstance(kMsgSendCID, NULL, kIMsgSendIID, (void **) &pMsgSend);   if (rv == NS_OK && pMsgSend)   {     printf("We succesfully obtained a nsIMsgSend interface....\n");        rv = nsComponentManager::CreateInstance(kMsgCompFieldsCID, NULL, kIMsgCompFieldsIID,                                              (void **) &pMsgCompFields);     if (rv == NS_OK && pMsgCompFields)    {       pMsgCompFields->SetTo("rhp@netscape.com", NULL);            // 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->SendMessageFile(pMsgCompFields, // nsIMsgCompFields                  *fields,                          mailFile,             // nsFileSpec                        *sendFileSpec,                          PR_TRUE,              // PRBool                            deleteSendFileOnCompletion,						              PR_FALSE,             // PRBool                            digest_p,						              nsMsgDeliverNow,      // nsMsgDeliverMode                  mode,                          tArray);              // nsIMsgSendListener array    }      }#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  printf("Releasing the interface now...\n");  pMsgSend->Release();   pMsgCompFields->Release();   return 0; }