gpt4 book ai didi

c - 使用C发送smtp电子邮件,不接受用户名和密码

转载 作者:行者123 更新时间:2023-11-30 15:57:02 24 4
gpt4 key购买 nike

我正在尝试向我的电子邮件帐户发送一封简单的文本邮件,但由于某种原因我的代码无法正常工作。这就是我到目前为止所拥有的......

int SendStartUpMail(char* mailserver, int port, char* user, char* pass)
{
SOCKET sslSock;
SOCKADDR_IN sslInfo;
SSL_CTX *ctx;
SSL *ssl;

char bufferRecv[BUFFER_LEN];
char bufferSend[BUFFER_LEN];
int byte;

sslSock = openConnection(mailserver, port);
memset( bufferRecv, '\0', BUFFER_LEN );
byte = recv(sslSock,bufferRecv,BUFFER_LEN,0);
if(byte == SOCKET_ERROR)
return -1;
printf("%s\n",bufferRecv);

strcpy(bufferSend,"HELO\r\n");
send(sslSock,bufferSend,strlen(bufferSend),0);
memset( bufferRecv, '\0', BUFFER_LEN );
byte = recv(sslSock,bufferRecv,BUFFER_LEN,0);
if(byte == SOCKET_ERROR)
return -1;
printf("%s",bufferRecv);

strcpy(bufferSend,"STARTTLS\r\n");
send(sslSock,bufferSend,strlen(bufferSend),0);
memset( bufferRecv, '\0', BUFFER_LEN );
byte = recv(sslSock,bufferRecv,BUFFER_LEN,0);
if(byte == SOCKET_ERROR)
return -1;
printf("%s",bufferRecv);

SSL_library_init();
ctx = SSL_CTX_new(SSLv3_client_method());
if ( ctx == NULL )
return -1;
ssl = SSL_new(ctx);
if ( ssl == NULL )
return -1;
SSL_set_fd(ssl, sslSock);

if ( SSL_connect(ssl) == 1 )
{
strcpy(bufferSend,"HELO\r\n");
SSL_write(ssl,bufferSend,strlen(bufferSend));
memset( bufferRecv, '\0', BUFFER_LEN );
SSL_read(ssl,bufferRecv,BUFFER_LEN);
printf(">%s\n",bufferRecv);

strcpy(bufferSend,"AUTH LOGIN\r\n");
SSL_write(ssl,bufferSend,strlen(bufferSend));
memset( bufferRecv, '\0', BUFFER_LEN );
SSL_read(ssl,bufferRecv,BUFFER_LEN);
printf(">%s\n",bufferRecv);

strcpy(bufferSend,"USER c29tZXVzZXJuYW1lQGdtYWlsLmNvbQ==\r\n");
SSL_write(ssl,bufferSend,strlen(bufferSend));
memset( bufferRecv, '\0', BUFFER_LEN );
SSL_read(ssl,bufferRecv,BUFFER_LEN);
printf(">%s\n",bufferRecv);

strcpy(bufferSend,"PASS c29tZXBhc3N3b3Jk\r\n");
SSL_write(ssl, bufferSend,strlen(bufferSend));
memset( bufferRecv, '\0', BUFFER_LEN );
SSL_read(ssl,bufferRecv,BUFFER_LEN);
printf(">%s\n",bufferRecv);
}
else
{
printf("Error on SSL_connect\n");
SSL_free(ssl);
SSL_CTX_free(ctx);
close(sslSock);
return -1;
}
SSL_free(ssl);
SSL_CTX_free(ctx);
close(sslSock);

}

当我运行此代码时,我从 smtp 服务器收到一些消息:

> 220 mx.google.com ESMTP 
> 250 mx.google.com at your service
> 220 2.0.0 Ready to Start TLS
> Conected with RC4-SHA encryption
> 250 mx.google.com at your service
> 334
> 334
> 535-5.7.1 Useername and Password not accepted

正如你所看到的,他们说我的密码和用户名错误,但我知道,这并没有错。我在发送之前使用 Base64 编码对我的用户名和密码进行编码,我使用此网站对它们进行编码 http://base64-encoder-online.waraxe.us/我使用端口 587。

我的问题是我还需要做些什么吗???谢谢。

我还尝试使用 Google 两步验证应用程序特定密码,但仍然无法登录。

我尝试连接到 hotmail,但收到了不同的错误,而不是错误 535

451 Request action aborted: local error in processing

最佳答案

使用我自己的帐户进行测试,AUTH LOGIN 不起作用,但 AUTH PLAIN 工作得很好:

250 ENHANCEDSTATUSCODES
auth plain
334
c29tZXVzZXJAZ21haWwuY29tAHNvbWV1c2VyQGdtYWlsLmNvbQBzb21lcGFzc3dvcmQ=
235 2.7.0 Accepted

这是 someuser@gmail.com\x00someuser@gmail.com\x00somepassword 的 Base64 编码版本。

关于c - 使用C发送smtp电子邮件,不接受用户名和密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10761846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com