|
I developed a SMTP tool several years ago (using win 98) and it worked well.
Now I need to send email in my app, so I test the SMTP tool again - it is not working now.
I downloaded several samples from CP articles, all of them are not working.
I am wondering why?
Is my OS (win2k) problem or anti-virus software blocked mail or something else?
Any suggestion?
|
|
|
|
|
check whether your SMTP server is open.
and what's your smtp function return value?
it's my pleasure to make friend with you.
|
|
|
|
|
includeh10 wrote: anti-virus software blocked mail
Anti-virus and firewall software is one of the most common causes of the problem you are experiencing. It's also possible that your ISP is blocking port 25 (some do, some don't) in an effort to reduce spam on their network. Without more information such as what operation it's failing on (connect, send, etc.) it's hard to tell.
Have you tried disabling your anti-virus and/or firewall and then running your app?
I am a lean mean ground beef machine!!!
|
|
|
|
|
Here is info:
1. none of commands return SOCKET_ERROR.
2. for QUIT command, ::recv() returns zero - this should be OK
3. ::gethostbyname("www.mycompany.com") - I use my company's domain, is this problem?
Thanks.
|
|
|
|
|
If your SMTP client does not handle authentication the first thing I would check is to make sure that the server you are connecting to does not require it. Also make sure that the server allows relaying from the location you are connecting from (it probably does if it's an internal company server but it's always best to make sure).
If that doesn't provide any answers I would load up a packet sniffer and monitor the transmissions between your application and the SMTP server. This should give you a better idea of how well the server is responding to your client. It's possible the server is returning an error that your client is not handling (hard to say without seeing the code).
If neither of those provide you with any answers you might want to try installing a bare bones SMTP server on a test machine and seeing if your client (and the other examples you have downloaded) works with it.
I am a lean mean ground beef machine!!!
|
|
|
|
|
Here are all test code, are there errors?
#define CHECK(iStatus) \
if(iStatus==SOCKET_ERROR) return 0;\
if(iStatus==0) return 0
#define EOL "\r\n"
BOOL TestSend()
{
const char*pszServer="www.mycompany";
const char*pszSmtpEmail ="myemail@hotmail.com";
const char*pszSenderEmail ="myemail@hotmail.com";
const char*pszSubject ="my subject";
const char*pszReceiver ="myemail@hotmail.com";
const char*pszBody ="the body";
const char*pszSenderName ="myemail@hotmail.com";
char sz[1024];
char wa[1024];
char szBuffer[4096];
char waTime[270];
int iRet;
HOSTENT* pHost=::gethostbyname(pszServer);
if(pHost==0) return 0;
SOCKET hSock=socket(PF_INET,SOCK_STREAM,0);
if(hSock==INVALID_SOCKET) return 0;
SERVENT*pServer=::getservbyname("mail",0);
const int iPort=pServer?pServer->s_port:IPPORT_SMTP;
SOCKADDR_IN sockAddr;
sockAddr.sin_family =AF_INET;
sockAddr.sin_port =iPort;
sockAddr.sin_addr =*((LPIN_ADDR)*pHost->h_addr_list);
if(::connect(hSock,(PSOCKADDR) &sockAddr,sizeof(sockAddr)))
{
return 0;
}
iRet=::recv(hSock,szBuffer,sizeof(szBuffer),0);
CHECK(iRet);
wsprintf(sz,"HELO %s%s","microsoft [111.122.1.12]",EOL);
CHECK(::send(hSock,sz,strlen(sz),0));
CHECK(::recv(hSock,szBuffer,sizeof(szBuffer),0));
wsprintf(sz,"MAIL FROM: <%s>%s",pszSmtpEmail,EOL);
CHECK(::send(hSock,sz,strlen(sz),0));
CHECK(::recv(hSock,szBuffer,sizeof(szBuffer),0));
wsprintf(sz,"RCPT To: <%s>%s",pszReceiver,EOL);
CHECK(::send(hSock,sz,strlen(sz),0));
CHECK(::recv(hSock,szBuffer,sizeof(szBuffer),0));
wsprintf(sz,"DATA%s",EOL);
CHECK(::send(hSock,sz,strlen(sz),0));
CHECK(::recv(hSock,szBuffer,sizeof(szBuffer),0));
strcpy(waTime,T("Date: "));
::GetDateFormat(0x409,0,0,T("ddd,dd MMM yyyy"),wa,200);
strcat(waTime,wa);
strcat(waTime,T(" "));
::GetTimeFormat(0x409,0,0,T("HH:mm:ss"),wa,200);
strcat(waTime,wa);
char szHead[350];
strcpy(szHead,"From: ");
strcat(szHead,pszSenderName );
strcat(szHead,"<");
strcat(szHead,pszSenderEmail);
strcat(szHead,">");
strcat(szHead,"\r\n");
strcat(szHead,"To: ");
strcat(szHead,pszReceiver);
strcat(szHead,"\r\n");
strcat(szHead,"Subject: ");
strcat(szHead,pszSubject );
strcat(szHead,"\r\n");
strcat(szHead,waTime);
strcat(szHead,"\r\n");
strcat(szHead,"X-Mailer: Outlook Express 1.00\r\nMIME-Version: 1.0\r\nContent-Type: text/plain;\r\n\tcharset=\"iso-8859-1\"\r\nContent-Transfer-Encoding: 7bit\r\n\r\n");
wsprintf(sz,szHead);
CHECK(::send(hSock,sz,strlen(sz),0));
char szBody[4800];
strcpy(szBody,pszBody );
strcat(szBody,"\r\n\r\n");
CHECK(::send(hSock,szBody,strlen(szBody),0));
wsprintf(sz,"%s.%s",EOL,EOL);
CHECK(::send(hSock,sz,strlen(sz),0));
CHECK(::recv(hSock,szBuffer,sizeof(szBuffer),0));
wsprintf(sz,"QUIT%s",EOL);
CHECK(::send(hSock,sz,strlen(sz),0));
iRet=::recv(hSock,szBuffer,sizeof(szBuffer),0);
closesocket(hSock );
WSACleanup();
return 1;
}
modified on Thursday, August 13, 2009 10:44 PM
|
|
|
|
|
For future reference please wrap your code postings in a <pre></pre> code block so that it's easier to read.
I am a lean mean ground beef machine!!!
|
|
|
|
|
Disregard my last post about recv()...my meds are making me way too fuzzy
Ok, I was able to compile and run it and everything worked fine after a couple of changes. The first problem is with the CHECK() macro:
#define CHECK(iStatus) \
if(iStatus==SOCKET_ERROR) return 0;\
if(iStatus==0) return 0
DO NOT DO THIS! When this macro is expanded by the preprocessor the send or recv operation passed as iStatus will be executed twice:
if(::send(hSock,sz,strlen(sz),0)==SOCKET_ERROR) return 0;
if(::send(hSock,sz,strlen(sz),0)==0) return 0
Instead you might try something like this (until you get everything fixed):
#define CHECK(iStatus) \
{ \
int result = iStatus; \
if(result==SOCKET_ERROR) return 0; \
if(result==0) return 0; \
}
Every email client I tried did not like the date format included in the message header. The following change should work:
::GetDateFormat(0x409,0,0,T("dd MMM yyyy"),wa,200);
I am a lean mean ground beef machine!!!
|
|
|
|
|
I was wondering how to intercept a WM_ specific message into a C++ class, I need to use the RegisterDeviceNotification function to register a specific WM_ message (I need a window here right?) and then intercept it and call the appropriate function
The C++ class should be included in any project, from a console one to a win32 to a mfc one. My idea is to create the skeleton of a win32 window and then use the WndProc for that window, is this stupid?
Is there any (surely) better solution?
---
|
|
|
|
|
You definitely need to have a Window Proc to recieve your message, because it is associated specifically with a registered Windows class. The documentation over at MSDN should show you how. See this: Windows Procedures Overview[^]
You can also define your own custom Windows messages using a define, and by selecting a value above WM_USER.
|
|
|
|
|
an own WinProc is the generic solution. But be aware that it dont gets "spaghetti ocde"
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
If I put the WinProc function in my class, it will need a hwnd handle I think.
What handle am I supposed to give it? Should I require one to the application which is going to use my class? (this would exclude console apps, that's just a pity)
---
|
|
|
|
|
yes you need a hwnd for it. The main hwnd of the app is fine.
If you havent a hwnd in your app, you must create one. It is common use to have in this cases an invisible (or minimized) window. Believe me
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
Ok the invisible window seems the right way.
Thank you all guys
---
|
|
|
|
|
One approach would be to store all message processing objects in a std::map<> container. Although this will only give you a 1 to 1 relationship between the expected window message and the object which handles it you'll have a nice start to begin expanding. When you receive the device notification message you can retrieve the object for that message and then call the appropriate method to handle the operation.
void HandleDeviceMessage(UINT msg, WPARAM wParam, LPARAM lParam)
{
ProcObject *obj;
std::map<UINT, ProcObject*>::iterator iter;
iter = m_DevNotifyMap.find(msg);
if(iter == m_DevNotifyMap.end()) {
return;
}
iter->second->OnNotification(msg, wParam, lParam);
}
I am a lean mean ground beef machine!!!
|
|
|
|
|
Recently, I develop Internet Explorer browser extension.
To put it concretely,
During Browser Extension[^], I applied Adding Button[^] to launch for my application (aka MyApp).
After installation, I could not see MyApp button in IE7, IE8 default toolbar because new extension button attached last position in toolbar.
So, I want to ask to customer after installation and arrange MyApp button to first in toolbar. like below
"Can I arrange MyApp's button to first order in toolbar ?"
But, I don't find any idea, method that control browser button order in toolbar.
(I try to find button order information in registry and to control browser event.)
Anybody have idea?
ref msdn
Browser Extension[^]
Addinb Button[^]
|
|
|
|
|
I'm automating Word and when I call a function that doesn't return for a long time (for example a call to
app.Run(_T("FilePrint")); ) it tends to freeze the UI of my app until it returns from the call, so I tried to run this code from a worker thread, but then COM complains and throws an exception RPC_E_WRONG_THREAD - "0x8001010E: The application called an interface that was marshalled for a different thread."
How can I solve this problem?
btw, there's an explanation about RPC_E_WRONG_THREAD in MSDN - INFO: Explanation of RPC_E_WRONG_THREAD Error[^], but I couldn't figure out anything from it.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Could you do all of the automation, including creation of the Word object, on the worker thread?
Basically you're running foul of COM single-threaded apartments and things, I think. This article[^] explains them well.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I read the article about apartments and replaced CoInitialize(NULL); with CoInitializeEx(NULL, COINIT_MULTITHREADED); in both my threads, but it still gives me the exact same error "The application called an interface that was marshalled for a different thread."
It's not really necessary for me to use multiple threads, I'm just doing it because I don't want my UI to block while I'm waiting for the COM method call to return. Do you know if there is some way to make a non-blocking COM method call akin to PostMessage vs SendMessage (I might post this as a new question on the forum btw).
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
sashoalm wrote: It's not really necessary for me to use multiple threads, I'm just doing it because I don't want my UI to block while I'm waiting for the COM method call to return
Which is commendable...
sashoalm wrote: Do you know if there is some way to make a non-blocking COM method call
This[^] is the only thing I remember - and that a) needs support from the COM server (Word doesn't provide it) and b) can't handle automation interfaces (which is probably one reason WHY Word doesn't provide it).
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
[I could have sworn I'd posted this message before...]
I've been playing with a little Excel automation sample I've got, adding a) Word automation, and b) multi-threading to it. I've ended up with this code that a) creates a Word instance on the main thread and b) calls that Word instance on a different thread. And the call succeeds, returning the expected value!
#include <boost/thread.hpp>
#import "libid:00020905-0000-0000-C000-000000000046" version("1.6") auto_search no_dual_interfaces rename("RGB", "wordRGB") rename("ReplaceText", "wordReplaceText") rename("FindText", "wordFindText") rename("ExitWindows", "wordExitWindows")
void GetActiveDocName(Word::_ApplicationPtr const& wd, _bstr_t& name)
{
try
{
name = wd->ActiveDocument->Name;
}
catch(_com_error& e)
{
name = L"No name";
}
}
int _tmain(int argc, _TCHAR* argv[])
{
CoInitializeEx(0, COINIT_MULTITHREADED);
{
Word::_ApplicationPtr wd;
if (SUCCEEDED(wd.CreateInstance(__uuidof(Word::Application))))
{
wd->Documents->Add();
_bstr_t name;
boost::thread getName(GetActiveDocName, boost::cref(wd), boost::ref(name));
getName.join();
std::cout << (char*)name << std::endl;
}
}
CoUninitialize();
return 0;
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hello!
I'm trying to make an internet monitoring application to log all the URLs visited by the user. Something like http://www.ematrixsoft.com/website-spy-monitor-software.htm
I tried using a sniffer library as suggested at http://www.codeproject.com/KB/IP/URLLogger.aspx
but had problems with HTTPS URLs because it seems that no only the content of the page is encrypted, but also the URL itself.
Do you have an idea of a "simple" method to catch all the visited URLs from any browser?. I can use a library (Free or not) if necessary.
Thanks.
|
|
|
|
|
televes wrote: Do you have an idea of a "simple" method to catch all the visited URLs from any browser?
No. Encryption is used to prevent exactly what you are trying to do. Since the URL may contain arguments for a GET operation the request and response headers are also encrypted. Attempting to subvert this is typically frowned upon as it becomes a potential exploit for use by Spyware.
I am a lean mean ground beef machine!!!
modified on Thursday, August 13, 2009 6:40 PM
|
|
|
|
|
|
No, not in the middle, in the client machine. In fact, I have discovered a library to do this:
http://www.komodia.com/index.php?page=interceptor.html
|
|
|
|
|