Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 04-21-2012, 11:08 PM   #1
woodx99
Junior Member
woodx99 began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Apr 2012
Device: kindle touch
A problem: call calibre-smtp.exe by CreateProcess in C++

Hello, everyone ,
I am a newer to calibre. Recently I want to send a email by call calibre-smtp.exe using CreateProcess() function in C++. The result is the CreateProcess() function return success, but maybe calibre-smtp.exe does not work, And nothing happend. so I donot call CreateProcess(), and changed to system() function, I doesnot work too.
But I run the calibre-smtp.exe and its param in cmd line (OS: windows7 64bit), it worked fine and email can be send successfully. The cmd line is:
"C:\Program Files (x86)\Calibre2\calibre-smtp.exe" -e SSL -r smtp.qq.com -u myuserid -p mypassword --port 465 -v -s "Email_title" xx@qq.com yy@foxmail.com "mailBody"

what is the matter? Do anyone know it?

woodx99 is offline   Reply With Quote
Old 04-24-2012, 09:20 PM   #2
woodx99
Junior Member
woodx99 began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Apr 2012
Device: kindle touch
Can someone give me a idea about this problem?

Can someone give me a idea about this problem?
woodx99 is offline   Reply With Quote
Old 04-24-2012, 09:32 PM   #3
PeterT
Grand Sorcerer
PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.
 
PeterT's Avatar
 
Posts: 12,167
Karma: 73448616
Join Date: Nov 2007
Location: Toronto
Device: Nexus 7, Clara, Touch, Tolino EPOS
Maybe if you post the code you are using, or a portion of it so people can see exactly what you are doing.
PeterT is offline   Reply With Quote
Old 04-25-2012, 01:07 AM   #4
PeterT
Grand Sorcerer
PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.PeterT ought to be getting tired of karma fortunes by now.
 
PeterT's Avatar
 
Posts: 12,167
Karma: 73448616
Join Date: Nov 2007
Location: Toronto
Device: Nexus 7, Clara, Touch, Tolino EPOS
For what it's worth.... this worked for me. Sorry I am NOT a c++ programmer; just found some examples on the web and modified them.

Spoiler:

Code:
	STARTUPINFO si;
    PROCESS_INFORMATION pi;

	WCHAR pCalibre[] = L"\"C:\\Program Files (x86)\\Calibre2\\calibre-smtp.exe\" -e SSL -r smtp.qq.com -u myuserid -p mypassword --port 465 -v -s \"Email_title\" xx@qq.com yy@foxmail.com \"mailBody\"";

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );

//    if( argc != 2 )
//    {
//        printf("Usage: %s [cmdline]\n", argv[0]);
//        return -1;
//    }

    // Start the child process. 
    if( !CreateProcess( NULL,   // No module name (use command line)
        pCalibre,       // Command line
        NULL,           // Process handle not inheritable
        NULL,           // Thread handle not inheritable
        FALSE,          // Set handle inheritance to FALSE
        0,              // No creation flags
        NULL,           // Use parent's environment block
        NULL,           // Use parent's starting directory 
        &si,            // Pointer to STARTUPINFO structure
        &pi )           // Pointer to PROCESS_INFORMATION structure
    ) 
    {
        printf( "CreateProcess failed (%d).\n", GetLastError() );
        return -1;
    }

    // Wait until child process exits.
    WaitForSingleObject( pi.hProcess, INFINITE );

    // Close process and thread handles. 
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );
	
	return 0;
PeterT is offline   Reply With Quote
Old 04-25-2012, 04:26 AM   #5
woodx99
Junior Member
woodx99 began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Apr 2012
Device: kindle touch
Blow is my full test source code:

Blow is my full test source code:

#include "stdafx.h"

#include "Windows.h"
#include "Winbase.h"


int main(int argc, char* argv[])
{
STARTUPINFO startinfo;
PROCESS_INFORMATION processinfo;
memset(&startinfo, 0, sizeof(STARTUPINFO));
startinfo.cb = sizeof(STARTUPINFO);
startinfo.lpReserved = NULL;
memset(&processinfo, 0, sizeof(PROCESS_INFORMATION));


const char* psExeName = "C:\\Program Files (x86)\\Calibre2\\calibre-smtp.exe";
char szCmdLine[4096];
strcpy(szCmdLine, "C:\\Program Files (x86)\\Calibre2\\calibre-smtp.exe -e SSL -r smtp.qq.com -u myuserid -p mypwd --port 465 -v -s \"Email_title\" from@qq.com to@foxmail.com \"mailBody\"");
const char* psCurrDir = "C:\\Program Files (x86)\\Calibre2";

if(CreateProcess(psExeName, szCmdLine, NULL, NULL, FALSE, CREATE_NO_WINDOW|DETACHED_PROCESS,
NULL, psCurrDir, &startinfo, &processinfo)==0)
{
printf("Create process failed.\n");
return -1;
}
printf("Create process ok.\n");

return 0;
}


==== This code can work, and print "Create process ok", but No mail has been sent.
woodx99 is offline   Reply With Quote
Old 04-25-2012, 04:37 AM   #6
woodx99
Junior Member
woodx99 began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Apr 2012
Device: kindle touch
Thanks

thanks to PeterT, his code does worked ok. I found my bug is that DETACHED_PROCESS flag is not necessary. And thanks everyone.
woodx99 is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
calibre-parallel.exe twice? sideburnt Calibre 12 03-24-2012 08:51 PM
Help! Need calibre installer in .exe, not .msi jkoerner Recipes 0 08-18-2011 07:28 PM
kobo reader stops calibre.exe remaus Devices 3 07-11-2011 10:11 PM
calibre-parallel.exe crashes on book import domee Calibre 2 07-06-2011 08:06 AM
Unhandled exception in calibre.exe (python26.dll) jusmee Calibre 0 12-14-2009 12:53 AM


All times are GMT -4. The time now is 04:29 AM.


MobileRead.com is a privately owned, operated and funded community.