我想连接到邮件服务器来阅读邮件。比如我有一个outlook地址toto@outlook.com,我想获取这个邮箱的所有邮件,并且能够阅读。所以我相信我只需要做一个客户端,但是:我如何联系和连接到这种类型的服务器,我如何听取答案?
这是我当前的客户端代码:
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
int main()
{
struct protoent *pe;
int fd_client;
struct sockaddr_in s_in;
int port;
char *ip;
char buff[4096];
ip = strdup("157.56.242.251"); // I get it while calling "ping outlook.com"
port = 210;
pe = getprotobyname("TCP");
fd_client = socket(AF_INET, SOCK_STREAM, pe->p_proto);
s_in.sin_family = AF_INET;
s_in.sin_port = htons(port);
s_in.sin_addr.s_addr = inet_addr(ip);
if (connect(fd_client, (struct sockaddr *)&s_in, sizeof(s_in)) == -1)
{
if (close(fd_client) == -1)
return (-1);
fprintf(stderr, "Failed to connect\n");
return (-1);
}
//From here I don't know what to do, so I tried this
recv(fd_client, buff, 4096, 0);
printf("%s\n",buff);
write(fd_client, "Hello !\n", strlen("Hello !\n"));
//To Here
if (close(fd_client) == -1)
return (-1);
return (0);
}
提前致谢。