在c中发送电子邮件,服务器在我发送正文后从不回复

在c中发送电子邮件,服务器在我发送正文后从不回复,c,sockets,telnet,winsock,winsock2,C,Sockets,Telnet,Winsock,Winsock2,我创建了一个用c语言发送电子邮件的小程序。 我做了3个功能: 连接:要使用套接字连接到服务器, SendAndRecieve:要向邮件服务器发送和接收邮件, SendAnEmail:编写SendAndRecieve将发送的文本 Connect和SENDERCIEVE工作正常。 我的问题是SendAnEmail。我不知道如何完成数据步骤 对于每个命令,我都会收到服务器的答案:250****** 但对于data one,它会在最后一个句号后的前354个位置回复,但不会在250个位置回复。我认为它与t

我创建了一个用c语言发送电子邮件的小程序。 我做了3个功能: 连接:要使用套接字连接到服务器, SendAndRecieve:要向邮件服务器发送和接收邮件, SendAnEmail:编写SendAndRecieve将发送的文本

Connect和SENDERCIEVE工作正常。 我的问题是SendAnEmail。我不知道如何完成数据步骤

对于每个命令,我都会收到服务器的答案:250****** 但对于data one,它会在最后一个句号后的前354个位置回复,但不会在250个位置回复。我认为它与telnet是相同的协议。 最后一个止点=车身末端。 但它不起作用。邮件服务器从不回复

有人知道告诉服务器我完成了正文编写的解决方案吗

代码

套接字连接(字符*服务器名称,未签名的短端口)
{
char buf[1024]={0};
int res_l=0;
int nbrecv;
服务器sockaddr中的结构sockaddr\u;
结构hostent*服务器hostent;
套接字到\u服务器\u套接字=0;
serverHostEnt=gethostbyname(服务器名称);
如果(serverHostEnt==NULL){
res_l=h_errno;
返回(套接字)-1;}
memcpy(&serverSockAddr.sin\u addr,serverHostEnt->h\u addr,serverHostEnt->h\u length);
serverSockAddr.sinu port=htons(端口)/
serverSockAddr.sin_family=AF_INET;
/*创建套接字*/
to_server_socket=socket(AF_INET,SOCK\u STREAM,0);
/*连接请求*/
if(连接到服务器套接字(结构sockaddr*)和服务器sockaddr,sizeof(服务器sockaddr))<0
返回(插座)-3;
而(!buf[0])nbrecv=recv(to_server_socket,buf,1024,0);
printf(“欢迎消息:%s\n”,buf);
返回_服务器_套接字;
}
void send和receive(套接字到服务器的套接字,char*messagesend)
{
char-bufreceive[1024];
整数大小、返回值、nbrecv;
大小=(int)strlen(messagesend);
//发送消息
retVal=send(发送到服务器的套接字,messagesend,大小,0);
printf(“特使:%s\n”,messagesend);
//等待答案
memset(bufreceive,01024);
而(!bufreceive[0])
nbrecv=recv(到服务器插槽,bufreceive,1024,0);
printf(“重复:%s\n”,bufreceive);
}             
void SendAnEmail(套接字套接字)
{
//埃洛
SendAndReceive(sock,“EHLO localhost\r\n”);
//寄自
发送和接收(sock),“邮件发件人:
RFC821说

该过程的第三步是DATA命令

        DATA <CRLF>

     If accepted, the receiver-SMTP returns a 354 Intermediate reply
     and considers all succeeding lines to be the message text.
     When the end of text is received and stored the SMTP-receiver
     sends a 250 OK reply.

     Since the mail data is sent on the transmission channel the end
     of the mail data must be indicated so that the command and
     reply dialog can be resumed.  SMTP indicates the end of the
     mail data by sending a line containing only a period.  A
     transparency procedure is used to prevent this from interfering
     with the user's text (see Section 4.5.2).
数据
如果接受,则接收方SMTP返回354中间回复
并将所有后续行视为消息文本。
当SMTP接收器接收并存储文本结尾时
发送一个250 OK的回复。
由于邮件数据是在传输信道上发送的,因此
必须指示邮件数据的类型,以便命令和
可以恢复回复对话框。SMTP表示回复结束
通过发送仅包含句点的行来发送数据。a
透明程序用于防止这种干扰
带有用户文本(见第4.5.2节)。
所以你需要在你的身体后面发送一条只有一个周期的线

如果您在
数据之后等待250,那也将是一个错误。您首先得到354,然后是仅在周期行之后的250


也许一次只发送一行,而不是将主题和正文集中在一起?我忘了添加SendAndRecieve功能:请编辑您的问题以添加信息或代码。标签下面有一个链接。我忘了添加SendAndRecieve功能。我也尝试过。单独发送句号。但服务器从未回答我。我可以继续写东西示例:sendandercieve(sock,“subject-subject\r\n\r\n”);sendandercieve(sock,“body\r\n”);sendandercieve(sock),。\r\n);Ofc我在这一点上做了一些修改。谢谢你的回答。我的解释不会失败。我有:发送:数据/接收:354------/发送:主题:主题/主体///现在服务器必须回复250----但它不会。尝试发送“\r\n.\r\n”作为您的经期专用线,为了确保如果您的身体没有以“\r\n”结尾,经期本身仍然在一条线上对不起,“经期专用线”是什么意思?来自上面的RFC文本。data命令后面的数据由一行终止,其中只有一个句点字符。假设a
recv()将在TCP连接中立即给您一个完整的响应行。您应该将TCP连接看作是一个字符流而不是一系列数据包。
Welcome message : 220 mwinf5d05 ME ESMTP server ready

S: EHLO localhost

R: 250-mwinf5d05 hello [10.162.66.36], pleased to meet you
250-HELP
250-AUTH LOGIN PLAIN
250-SIZE 44000000
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 OK

S: MAIL FROM: <blablabla@orange.fr>

R: 250 2.1.0 <blablabla@orange.fr> sender ok

S: RCPT TO: <xapx35@gmail.com>

R: 250 2.1.5 <xapx35@gmail.com> recipient ok

S: DATA

R: 354 enter mail, end with "." on a line by itself

S: Subject: FlashRad

Ceci est un test.
.
        DATA <CRLF>

     If accepted, the receiver-SMTP returns a 354 Intermediate reply
     and considers all succeeding lines to be the message text.
     When the end of text is received and stored the SMTP-receiver
     sends a 250 OK reply.

     Since the mail data is sent on the transmission channel the end
     of the mail data must be indicated so that the command and
     reply dialog can be resumed.  SMTP indicates the end of the
     mail data by sending a line containing only a period.  A
     transparency procedure is used to prevent this from interfering
     with the user's text (see Section 4.5.2).