SMTP: all are not working?
-
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?
-
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?
-
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?
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!!!
-
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.
-
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?
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); // Receive initial response from SMTP server. CHECK(iRet); // Send HELO 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)); // Send MAIL FROM: wsprintf(sz,"MAIL FROM: <%s>%s",pszSmtpEmail,EOL); CHECK(::send(hSock,sz,strlen(sz),0)); CHECK(::recv(hSock,szBuffer,sizeof(szBuffer),0)); // Send RCPT TO: wsprintf(sz,"RCPT To: <%s>%s",pszReceiver,EOL); CHECK(::send(hSock,sz,strlen(sz),0)); CHECK(::recv(hSock,szBuffer,sizeof(szBuffer),0)); // Send DATA. wsprintf(sz,"DATA%s",EOL); CHECK(::send(hSock,sz,strlen(sz),0)); CHECK(::recv(hSock,szBuffer,sizeof(szBuffer),0)); ///szHead 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-Ver
-
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); // Receive initial response from SMTP server. CHECK(iRet); // Send HELO 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)); // Send MAIL FROM: wsprintf(sz,"MAIL FROM: <%s>%s",pszSmtpEmail,EOL); CHECK(::send(hSock,sz,strlen(sz),0)); CHECK(::recv(hSock,szBuffer,sizeof(szBuffer),0)); // Send RCPT TO: wsprintf(sz,"RCPT To: <%s>%s",pszReceiver,EOL); CHECK(::send(hSock,sz,strlen(sz),0)); CHECK(::recv(hSock,szBuffer,sizeof(szBuffer),0)); // Send DATA. wsprintf(sz,"DATA%s",EOL); CHECK(::send(hSock,sz,strlen(sz),0)); CHECK(::recv(hSock,szBuffer,sizeof(szBuffer),0)); ///szHead 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-Ver
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!!!
-
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); // Receive initial response from SMTP server. CHECK(iRet); // Send HELO 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)); // Send MAIL FROM: wsprintf(sz,"MAIL FROM: <%s>%s",pszSmtpEmail,EOL); CHECK(::send(hSock,sz,strlen(sz),0)); CHECK(::recv(hSock,szBuffer,sizeof(szBuffer),0)); // Send RCPT TO: wsprintf(sz,"RCPT To: <%s>%s",pszReceiver,EOL); CHECK(::send(hSock,sz,strlen(sz),0)); CHECK(::recv(hSock,szBuffer,sizeof(szBuffer),0)); // Send DATA. wsprintf(sz,"DATA%s",EOL); CHECK(::send(hSock,sz,strlen(sz),0)); CHECK(::recv(hSock,szBuffer,sizeof(szBuffer),0)); ///szHead 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-Ver
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 0DO 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 0Instead 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!!!