⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mailsend.c

📁 电子邮件指定地址海量发送
💻 C
字号:
/*---------------------------------------------------------------------------------
MailSend.c
			Base64Enc.c
						SheJingjing
---------------------------------------------------------------------------------*/

#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>

/*-------------------------
base64 encode function
-------------------------*/
void base64enc(char *instr,char *outstr)
{
        char * table="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
        int instr_len=0,i=0,j=0,pad=0;
        unsigned char buf1[4]="",buf2[4]="";
        instr_len=strlen(instr);
        pad=instr_len%3;
        for(i=0;i < instr_len;i=i+3)
        {
                if(instr_len - i == 2)
                {
                        buf1[0] = instr[i];
                        buf1[1] = instr[i+1];
                        buf2[0] = buf1[0] >> 2;
                        buf2[1] = (buf1[0] & 0x03) << 4 | buf1[1] >> 4;
                        buf2[2] = (buf1[1] & 0x0f) << 2;
                        buf2[3] = '=';
                        buf2[0] = table[buf2[0]];
                        buf2[1] = table[buf2[1]];
                        buf2[2] = table[buf2[2]];
                }
                else if(instr_len - i == 1)
                {
                        buf1[0] = instr[i];
                        buf2[0] = buf1[0] >> 2;
                        buf2[1] = (buf1[0] & 0x03) << 4;
                        buf2[2] = '=';
                        buf2[3] = '=';
                        buf2[0] = table[buf2[0]];
                        buf2[1] = table[buf2[1]];
                }
                else
                {
                        buf1[0] = instr[i];
                        buf1[1] = instr[i+1];
                        buf1[2] = instr[i+2];
                        buf2[0] = buf1[0] >> 2;
                        buf2[1] = (buf1[0] & 0x03) << 4 | buf1[1] >> 4;
                        buf2[2] = (buf1[1] & 0x0f) << 2 | buf1[2] >> 6;
                        buf2[3] = buf1[2] & 0x3f;
                        buf2[0] = table[buf2[0]];
                        buf2[1] = table[buf2[1]];
                        buf2[2] = table[buf2[2]];
                        buf2[3] = table[buf2[3]];
                }
                strncat(outstr,buf2,4);
        }
}

int main()
{
	char ServerAddress[27]="",FromMail[512]="",SendMail[512]="",UserName[512]="",Passwd[512]="";
	int ServerPort,SendNum,time;
	printf("Input The ServerAddress: ");
	scanf("%s",&ServerAddress);
	printf("Input The ServerPort: ");
	scanf("%d",&ServerPort);
	printf("Input The MailFrom(username@domain.com): ");
	scanf("%s",&UserName);
	printf("Input The MailFromPasswd: ");
	scanf("%s",&Passwd);
	printf("Input The MailTo(username@domain.com): ");
	scanf("%s",&SendMail);
	printf("Input The SendNum: ");
	scanf("%d",&SendNum);
	printf("Input The SendTime(30000 = 1/s): ");
	scanf("%d",&time);
	char UserEncName[512]="";
	char PasswdEnc[512]="";
	base64enc(UserName,UserEncName);
	base64enc(Passwd,PasswdEnc);
	printf("The ServerAddress is %s\n",ServerAddress);
	printf("The ServerPort is %d\n",ServerPort);
	printf("The UserName is %s\n",UserEncName);
	printf("The Passwd is %s\n",PasswdEnc);
	printf("The SendMail is %s\n",SendMail);
	printf("The SendNum is %d\n",SendNum);
	printf("The SendTime is %d\n",time);

	int sockfd,socktd;
	struct in_addr {
		unsigned long int s_addr;
	};
	struct sockaddr_in {
		short int sin_family;
		unsigned short int sin_port;
		struct in_addr sin_addr;
		unsigned char sin_zero[8];
	}dest_addr;
	int i;
	for(i=1;i<=SendNum;i++)
		{
		sockfd=socket(AF_INET,SOCK_STREAM,0);
		if(sockfd < 0) 
			{printf("Take the socketing ...... Error\n");}
		dest_addr.sin_family=AF_INET;
		dest_addr.sin_port=htons(ServerPort);
		dest_addr.sin_addr.s_addr=inet_addr(ServerAddress);
		bzero(&(dest_addr.sin_zero),8);
		socktd=connect(sockfd,(struct sockaddr*)&dest_addr,sizeof(struct sockaddr));
		if(socktd < 0)
			{printf("Connecting %s ...... Error\n",inet_ntoa(dest_addr.sin_addr));}
		usleep(time);
		int sock,len;
		char *msg="ehlo feng\r\n";
		len=strlen(msg);
		sock=send(sockfd,msg,len,0);
		if(sock < 0)
			{printf("Send ...... Error\n");}
		usleep(time);
		char *login="AUTH LOGIN\r\n";
		sock=send(sockfd,login,strlen(login),0);
		if(sock < 0)
			{printf("Login Error!\n");}
		usleep(time);
		char *LoginUser=UserEncName;
		sock=send(sockfd,LoginUser,strlen(LoginUser),0);
                if(sock < 0)
                        {printf("LoginUser Error!\n");}
                usleep(time);
		sock=send(sockfd,"\r\n",strlen("\r\n"),0);
		if(sock < 0)
                        {printf("LoginUserEnter Error!\n");}
		usleep(time);
		char *LoginPasswd=PasswdEnc;
		sock=send(sockfd,LoginPasswd,strlen(LoginPasswd),0);
		if(sock < 0)
			{printf("LoginPasswd Error!\n");}
		usleep;
		sock=send(sockfd,"\r\n",strlen("\r\n"),0);
                if(sock < 0)
                        {printf("LoginPasswdEnter Error!\n");}
                usleep(time);
		sock=send(sockfd,"MAIL FROM: <",strlen("MAIL FROM: <"),0);
		if(sock < 0)
			{printf("Send Mailfrom ...... Error\n");}
		usleep(time);
		char *MailFromByte=UserName;
		sock=send(sockfd,MailFromByte,strlen(MailFromByte),0);
		if(sock < 0)
			{printf("Send MailFromByte Error!\n");}
		usleep(time);
		sock=send(sockfd,">\r\nRCPT TO: <",strlen(">\r\nRCPT TO: <"),0);
			if(sock < 0)
                        {printf("Send RCPT TO Error!\n");}
		usleep(time);
		char *SendMailByte=SendMail;
		sock=send(sockfd,SendMailByte,strlen(SendMailByte),0);
                if(sock < 0)
			{printf("Send The SendMailByte_Mail Error!\n");}
		usleep(time);
		sock=send(sockfd,">\r\nData\r\n",strlen(">\r\nData\r\n"),0);
	        if(sock < 0)
	                {printf("Send Data...... Error\n");}
		usleep(time);
		const char *MailFromTo="From: <";
                sock=send(sockfd,MailFromTo,strlen(MailFromTo),0);
                if(sock < 0)
                        {printf("Send MailFrom...... Error\n");}
                usleep(time);
		sock=send(sockfd,MailFromByte,strlen(MailFromByte),0);
		if(sock < 0)
			{printf("Send The MailFromByte_Mail Error!\n");}
		usleep(time);
                sock=send(sockfd,">\r\nTo: <",strlen(">\r\nTo: <"),0);
                if(sock < 0)
                        {printf("Send MailFrom Enter...... Error\n");}
                usleep(time);
		sock=send(sockfd,SendMailByte,strlen(SendMailByte),0);
		if(sock < 0)
                        {printf("Send SendMailByte_Mail...... Error\n");}
                usleep(time);
		sock=send(sockfd,">\r\n",strlen(">\r\n"),0);
		if(sock < 0)
                        {printf("Send SendMailEnter_Mail...... Error\n");}
                usleep(time);
		const char *MailSubject="Subject: This is only a test mail! ^^\r\n\r\n";
	        sock=send(sockfd,MailSubject,strlen(MailSubject),0);
	        if(sock < 0)
	               	{printf("Send MailData...... Error\n");}
		usleep(time);
		char str[25];
		sprintf(str,"%d",i);
                sock=send(sockfd,str,strlen(str),0);
                if(sock < 0)
                        {printf("Send MailData...... Error\n");}
                usleep(time);
		char *MailDataEnd="\r\n.\r\n";
		if(i - SendNum == 0)
                        {usleep(100000);}
                else
                        {usleep(time);}
                sock=send(sockfd,MailDataEnd,strlen(MailDataEnd),0);
                if(sock < 0)
                        {printf("Send MailDataEnd...... Error\n");}
                usleep(time);		
		msg=NULL;
	        sock=recv(sockfd,msg,1024,0);
	        if(sock >= 0)
	                {printf(msg);
			printf("\n");}
		if(SendNum - i == 0)
			{usleep(100000);}
		else
			{usleep(time);}
		sock=send(sockfd,"QUIT\r\n",strlen("QUIT\r\n"),0);
		if(sock < 0)
			{printf("Send QUIT ...... Error\n");}
		msg=NULL;
		sock=recv(sockfd,msg,1024,0);
		if(sock >= 0)
			{printf(msg);
			printf("\n");}
		if(i - SendNum == 0)
                        {usleep(100000);}
		else
			{usleep(time);}
		printf("The %d Mail is Send!\n",i);
		if(i - SendNum == 0)
                        {printf("Send OK\n");}
		}	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -