Undisclosed-recipients
0 отговора
38 прегледа
Undisclosed-recipients
Мисля да правя програма която да изпраща мейл или sms за да ме подсеща за нещо.
Написал съм нещо подобно но в този си вид комуникацията с сървъра стига до някъде и спира:
Ако махна From: To: и Subject: писмото се праща но при получателя излиза To:unsisclosed-recipients
Някой може ли да каже какви промени да направя за да се праща писмото но и да се получава както трябва
#define MAILSTR_MAX_LEN 128
char MyMail[MAILSTR_MAX_LEN];
char OtherMail[MAILSTR_MAX_LEN];
#define MAILADDRESS "mymail@mymail.bg"
#include <stdio.h>
#include <winsock.h>
#include <stdlib.h>
void DieWithError(char*errorMessage) { fprintf(stderr,"%s:%d\n", errorMessage,WSAGetLastError()); exit(1); }
void main(int argc,char*argv[])
{
int sock;
struct sockaddr_in echoServAddr;
unsigned short echoServPort;
char *servIP;
char echoString[100];
char echoBuffer[100];
int echoStringLen;
int bytesRcvd,totalBytesRcvd;
WSADATA wsaData;
servIP="xxx.xxx.xxx.xxx";
echoServPort=25;
if(WSAStartup(MAKEWORD(2,0),&wsaData)!=0)
{
fprintf(stderr,"WSAStartup()failed");
exit(1);
}
strcpy (MyMail, "m@b.com");
strcpy (OtherMail, MAILADDRESS);
if((sock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP))<0)
DieWithError("socket()failed");
memset(&echoServAddr,0,sizeof(echoServAddr));
echoServAddr.sin_family=AF_INET;
echoServAddr.sin_addr.s_addr=inet_addr(servIP);
echoServAddr.sin_port=htons(echoServPort);
if(connect(sock,(struct sockaddr*)&echoServAddr,sizeof(echoServAddr))<0)
DieWithError("connect()failed");
strcpy(echoString,"helo proba \r\n");
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
totalBytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString, "MAIL FROM: <%s>\r\n", MyMail);
printf (echoString);
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString, "RCPT TO: %s\r\n", OtherMail);
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString, "DATA \r\n");
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString,"From: aaa@aaa.bg \r\n");
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString,"To: aaa@aaa.bg \r\n");
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString,"Subject: \r\n");
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString,"%s\r\n",argv[1]);
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString,"\r\n.\r\n");
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString,"quit\r\n");
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
Написал съм нещо подобно но в този си вид комуникацията с сървъра стига до някъде и спира:
Ако махна From: To: и Subject: писмото се праща но при получателя излиза To:unsisclosed-recipients
Някой може ли да каже какви промени да направя за да се праща писмото но и да се получава както трябва
#define MAILSTR_MAX_LEN 128
char MyMail[MAILSTR_MAX_LEN];
char OtherMail[MAILSTR_MAX_LEN];
#define MAILADDRESS "mymail@mymail.bg"
#include <stdio.h>
#include <winsock.h>
#include <stdlib.h>
void DieWithError(char*errorMessage) { fprintf(stderr,"%s:%d\n", errorMessage,WSAGetLastError()); exit(1); }
void main(int argc,char*argv[])
{
int sock;
struct sockaddr_in echoServAddr;
unsigned short echoServPort;
char *servIP;
char echoString[100];
char echoBuffer[100];
int echoStringLen;
int bytesRcvd,totalBytesRcvd;
WSADATA wsaData;
servIP="xxx.xxx.xxx.xxx";
echoServPort=25;
if(WSAStartup(MAKEWORD(2,0),&wsaData)!=0)
{
fprintf(stderr,"WSAStartup()failed");
exit(1);
}
strcpy (MyMail, "m@b.com");
strcpy (OtherMail, MAILADDRESS);
if((sock=socket(PF_INET,SOCK_STREAM,IPPROTO_TCP))<0)
DieWithError("socket()failed");
memset(&echoServAddr,0,sizeof(echoServAddr));
echoServAddr.sin_family=AF_INET;
echoServAddr.sin_addr.s_addr=inet_addr(servIP);
echoServAddr.sin_port=htons(echoServPort);
if(connect(sock,(struct sockaddr*)&echoServAddr,sizeof(echoServAddr))<0)
DieWithError("connect()failed");
strcpy(echoString,"helo proba \r\n");
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
totalBytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString, "MAIL FROM: <%s>\r\n", MyMail);
printf (echoString);
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString, "RCPT TO: %s\r\n", OtherMail);
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString, "DATA \r\n");
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString,"From: aaa@aaa.bg \r\n");
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString,"To: aaa@aaa.bg \r\n");
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString,"Subject: \r\n");
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString,"%s\r\n",argv[1]);
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString,"\r\n.\r\n");
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
sprintf (echoString,"quit\r\n");
echoStringLen=strlen(echoString);
if(send(sock,echoString,echoStringLen,0)!=echoStringLen)
DieWithError("send()sent a different number of bytes than expected");
bytesRcvd=0;
printf("Received:");
if((bytesRcvd=recv(sock,echoBuffer,100,0))<=0)
DieWithError("recv()failed or connection closed prematurely");
echoBuffer[bytesRcvd]='\0';
printf(echoBuffer);
Редактирано от supervisor на