Hey, i need your help :(.
Im working on a mail-downloader but it wont work (pop3) :(.
mail provider:www.gmx.net
It always say "Wrong ID+PW" why?

here is the code:

#include "stdafx.h" // includes are there ;)


//Prototypen

int startWinsock(void);

int main()

{
	char buf[256];
	long rc;
	SOCKET s;
	SOCKADDR_IN addr;

  rc=startWinsock();

  if(rc!=0)
  {

    printf("Fehler: startWinsock, fehler code: %d\n",rc); // failed

  }
  else
  {
    printf("Winsock gestartet!\n");
  }

  s=socket(AF_INET,SOCK_STREAM,0);

if(s==INVALID_SOCKET)

{

  printf("Fehler: Der Socket konnte nicht erstellt werden, fehler code: %d\n",WSAGetLastError()); // Failed

  return 1;

}

else

{

  printf("Socket erstellt!\n");

}

 memset(&addr,0,sizeof(SOCKADDR_IN)); 

addr.sin_family=AF_INET;

addr.sin_port=htons(110); 

addr.sin_addr.s_addr=inet_addr("213.165.64.22"); // pop.gmx.net



rc=connect(s,(SOCKADDR*)&addr,sizeof(SOCKADDR));

if(rc==SOCKET_ERROR)

{

  printf("Fehler: connect gescheitert, fehler code: %d\n",WSAGetLastError()); // failed

}

else

{

  printf("Verbunden mit gmx..\n");

}


recv(s,buf,sizeof(buf),0);
std::cout << buf << std::endl;


strcpy(buf, "user xxx@gmx.de");
send(s,buf,sizeof(buf),0);
//std::cout << buf << std::endl;

recv(s,buf,sizeof(buf),0);
std::cout << buf<< std::endl;

strcpy(buf, "pass xxx");
send(s,buf,sizeof(buf),0);
//std::cout << buf << std::endl;

recv(s,buf,sizeof(buf),0);
std::cout << buf<< std::endl;


closesocket(s);
WSACleanup();

  system("pause");
  return 0;

}

int startWinsock(void)

{

  WSADATA wsa;

  return WSAStartup(MAKEWORD(2,0),&wsa);

}

Here is a screenshot:

http://i29.tinypic.com/2cmpwcp.jpg

Thx :)
Daniel

Recommended Answers

All 5 Replies

Try to type like this

send(s, buf, strlen(buf)+1, 0);

or use the safe method lstrlen()

Hey thx for your answer but it doesnt work :(.
I get the message -Ok Pop server rdy

now the program should send the user blabla

then nothing happens

i made a cout below the send and it shows me in the console...
it seems that the program jumps over the send or something like that :(... then recv.. it waits but nothing happens -> soon timeout...

...

by the way i tested the same thing by another mail provider ( with my first code )..

it sends the user

then it asks for the password

my program sends the pass test

answer from the server : -Err unknown command

why?
pass password is right :x

rly confusing :S

Are you sure that format of the sent data just the same?
Maybe server wait's some structured packet.
I've found some algorithm that autorizes on the pop3 server
Messages to a server:
1. "USER <username>(witout '<>') \r\n" - username
2. "PASS <password>(witout '<>') \r\n" - password
3. "STAT\r\n" - mailbox statistics
4. "QUIT\r\n" - logout

And after each query you have to recieve tha answer

I hope it will help you.

recv(s,buf,sizeof(buf),0);
std::cout << buf << std::endl;


strcpy(buf, "user xxx@gmx.de \r\n");
send(s,buf,sizeof(buf),0);
//std::cout << buf << std::endl;

recv(s,buf,sizeof(buf),0);
std::cout << buf<< std::endl;

strcpy(buf, "pass xxx \r\n");
send(s,buf,sizeof(buf),0);
//std::cout << buf << std::endl;

recv(s,buf,sizeof(buf),0);
std::cout << buf<< std::endl;

now it asks: May i have your password

then

unknown command

then i deleted the \r\n again and then ... pw / id wrong again.

Dont know why it wont work but thx for your answer :))

You're assuming
a) the network has zero latency, by calling recv() directly after send()
b) that recv() will just stick around until a \r\n arrives - it won't.
c) that recv() will add a \0 to the end of the buffer to make it a proper C string - it won't do that either.

You need to seriously improve the recv() side of things to check for errors AND process the characters more carefully.

commented: I am weener agrees with this kiddo! +22
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.