C OpenSSL 登录 POP 邮件服务器

标签 c email openssl client pop3

我想用 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/

相关文章:

c - 将接口(interface)模块程序从 Fortran 导入到 C 中

C 程序在按 escape 时终止

objective-c - 我应该如何用电子邮件发送我自己格式的文件,我应该怎么做才能在我自己的 iOS 5 应用程序中打开它?

ios - Parse.com验证电子邮件并重定向到App

ssl - Wamp2 和 "The ordinal 942 could not be located in the dynamic link library LIBEAY.dll"

android - 为 Android 编译 OpenSSL 1.1.0

ruby - 在 Mac 上从 1.1 降级到 OPENSSL 版本 1.0

c - pthread_create - 如何创建单线程并在需要时在循环中调用它

c - 为什么作为命令行参数传入的 UTF-16 字符串的 hexdump 与直接在终端上的不同?

php - Laravel Mail::send() 发送到多个 to 或 bcc 地址