我想用 C 语言编写一个邮件客户端。我使用 openssl,但我有一个问题,当我使用像“USER example”这样与 telnet 配合使用的命令时,我总是得到一个“未知命令”。
所需的代码是:
int login(BIO *bio) {
unsigned char buf_print[4096]; //Used for WebPrintLine to
unsigned char user_log[] = {"USER me\n"};
if( WebSendLine(bio, user_log, strlen(user_log)) != 0) {
printf("Couldn't login.\n");
return -1;
}
WebPrintReturnLine(bio, buf_print, sizeof(buf_print));//Print the line to the display
}
还有:
//Send one line of data
int WebSendLine(BIO *bio, unsigned char buf_write[], int strlenbuf) {
/*
BIO_write will attempt to write bytes to the socket. It returns the number of bytes actually written, or 0 or -1. As with BIO_read, 0 or -1 does not necessarily indicate an error. BIO_should_retry is the way to find out. If the write operation is to be retried, it must be with the exact same parameters as before.
*/
if( BIO_write(bio, buf_write, strlenbuf) <= 0 ) {
if( ! BIO_should_retry(bio) )
return -1;
}
return 0;
}
我或多或少是个新手,所以我可能还不明白它是如何工作的。 我的问题是我必须做什么才能不从服务器返回“未知命令”?
我期待收到您的来信。
国王问候, 绿色环保
最佳答案
服务器需要回车和换行。您应该发送“USER example\r\n”
关于C OpenSSL 登录 POP 邮件服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24842653/