#include
#include
#include
#include
#include
#include
#include
#define MAX 512
int main()
{
int res, sockfd,i;
char cmd[MAX];
char buf[MAX];
FILE *fp;
struct sockaddr_in serveraddr;
struct sockaddr_in clientaddr;
sockfd=socket(AF_INET,SOCK_STREAM,0);
if(sockfd==-1)
{
printf("Error in creating socket");
exit(0);
}
serveraddr.sin_family = AF_INET;
serveraddr.sin_addr.s_addr = inet_addr("127.0.0.1");
serveraddr.sin_port = htons(25);
res = connect(sockfd, (struct sockaddr *) &serveraddr,sizeof(serveraddr));
if(res==-1)
{
printf("Error in nameing socket");
exit(0);
}
read(sockfd,buf,MAX);
printf("\n%s",buf);
write(sockfd,"HELO localhost",MAX);
read(sockfd,buf,MAX);
printf("\n%s",buf);
write(sockfd,"MAIL FROM: student@localhost",MAX);
read(sockfd,buf,MAX);
printf("\n%s",buf);
write(sockfd,"RCPT TO: root@localhost",MAX);
read(sockfd,buf,MAX);
printf("\n%s",buf);
fp=fopen("msg.txt","r");
write(sockfd,"DATA",MAX);
read(sockfd,buf,MAX);
printf("\n%s",buf);
while(!feof(fp))
{
fgets(fp,buf,MAX);
write(sockfd,buf,MAX);
}
write(sockfd,".\n\r",3);
read(sockfd,buf,MAX);
printf("\n%s",buf);
write(sockfd,"QUIT",MAX);
read(sockfd,buf,MAX);
printf("\n%s",buf);
}
Copyright © 2011 - All Rights Reserved - Softron.in
Template by Softron Technology