| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 875 人关注过本帖
标题:我这个出错了,我不知道怎么改,谢谢大家能帮忙
只看楼主 加入收藏
baiye00
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2013-9-29
收藏
 问题点数:0 回复次数:6 
我这个出错了,我不知道怎么改,谢谢大家能帮忙
#include<windows.h>
#include<stdio.h>
#include<WinSock.h>
#include<iostream>
using namespace std;
struct Base64Date6
{
unsigned int d4:6;
unsigned int d3:6;
unsigned int d2:6;
unsigned int d1:6;
};
//  协议中加密部分使用的是base64方法
char ConvertToBase64(char c6);
void EncodeBase64(char*dbuf,char*buf128,int len);
void SendMail(char*email,char*body,char* hostname ,short port,char *username,char *password);
int  OpenSocket(struct sockaddr *addr);
int main(int argc,char *argv[])
{
   
 
 char *EmailTo=argv[1];   
 char *host=argv[2];
 char *port=argv[3];
 
 char *user=argv[4];
 char *pass=argv[5];
 char *subject=argv[6];
 char *filename=argv[7];
 char *EmailContents=new char[20000];
 
 char *From=new char[128];
 sprintf(From,"From: <%s>\r\n",user);
 char *To=new char[128];
 sprintf(To,"To: <%s>\r\n",EmailTo);
 char *sub=new char[128];
 sprintf(sub,"Subject: %s\r\n\r",subject);
 
 short porttemp=0;
 for(int i=0;i<strlen(port);i++)
 {
            porttemp=porttemp*10+port[i]-'0';
    }
 FILE *fp;
 fp=fopen(filename,"rb");
 if(!fp)//error
        {     
               printf("File path error\n");           
               return false;      
        }
 fseek(fp, 0L, SEEK_END);
    int fileSize = ftell(fp);
    fseek(fp, 0L, SEEK_SET);
 cout<<fileSize<<endl;
 char content[fileSize];
 fread(content,1,fileSize,fp);
 cout<<content<<endl;
 fclose(fp);
 
 sprintf(EmailContents,"%s%s%s%s",From,To ,sub,content);
 cout<<EmailContents<<endl;
    SendMail(EmailTo,EmailContents,host,porttemp,user,pass);
 system("PAUSE");
    return 0;
}
char ConvertToBase64(char uc)
{
     if(uc <26)
     {
           return 'A'+uc;
     }
     if(uc <52)
     {
           return 'a'+(uc -26);
     }
     if(uc <62)
     {
           return '0'+(uc -52);
     }
     if(uc ==62)
     {
           return '+';
     }
     return '/';
}
// base64的实现
void EncodeBase64(char *dbuf,char *buf128,int len)
{
     struct Base64Date6*ddd =NULL;
     int i =0;
     char buf[256]={0};
     char *tmp =NULL;
     char cc ='\0';
     memset(buf,0,256);
     strcpy(buf,buf128);
     for(i =1;i <=len/3;i++)
     {
           tmp =buf +(i-1)*3;
           cc =tmp[2];
           tmp[2]=tmp[0];
           tmp[0]=cc;
           ddd =(struct Base64Date6*)tmp;
           dbuf[(i-1)*4+0]=ConvertToBase64((unsigned int)ddd->d1);
           dbuf[(i-1)*4+1]=ConvertToBase64((unsigned int)ddd->d2);
           dbuf[(i-1)*4+2]=ConvertToBase64((unsigned int)ddd->d3);
           dbuf[(i-1)*4+3]=ConvertToBase64((unsigned int)ddd->d4);
     }
     if(len %3==1)
     {
            tmp =buf +(i-1)*3;
            cc =tmp[2];
            tmp[2]=tmp[0];
            tmp[0]=cc;
            ddd =(struct Base64Date6*)tmp;
            dbuf[(i-1)*4+0]=ConvertToBase64((unsigned int)ddd->d1);
            dbuf[(i-1)*4+1]=ConvertToBase64((unsigned int)ddd->d2);
            dbuf[(i-1)*4+2]='=';
            dbuf[(i-1)*4+3]='=';
     }
     if(len%3==2)
     {
            tmp =buf+(i-1)*3;
            cc =tmp[2];
            tmp[2]=tmp[0];
            tmp[0]=cc;
            ddd =(struct Base64Date6*)tmp;
            dbuf[(i-1)*4+0]=ConvertToBase64((unsigned int)ddd->d1);
            dbuf[(i-1)*4+1]=ConvertToBase64((unsigned int)ddd->d2);
            dbuf[(i-1)*4+2]=ConvertToBase64((unsigned int)ddd->d3);
            dbuf[(i-1)*4+3]='=';
     }
     return;
}
// 发送邮件
void SendMail(char*email,char*body,char* hostname ,short port,char *username,char *password)
{
     int sockfd ={0};
     char buf[1500]={0};
     char rbuf[1500]={0};
     char login[128]={0};
     char pass[128]={0};
     WSADATA WSAData;
     struct sockaddr_in their_addr ={0};
     WSAStartup(MAKEWORD(2,2),&WSAData);
     memset(&their_addr,0,sizeof(their_addr));
     their_addr.sin_family =AF_INET;
     their_addr.sin_port =htons(port);
     hostent*hptr =gethostbyname(hostname);
     memcpy(&their_addr.sin_addr.S_un.S_addr,hptr->h_addr_list[0],hptr->h_length);
     printf("IP of %s is : %d:%d:%d:%d\n",
   hostname,
     their_addr.sin_addr.S_un.S_un_b.s_b1,
     their_addr.sin_addr.S_un.S_un_b.s_b2,
     their_addr.sin_addr.S_un.S_un_b.s_b3,
     their_addr.sin_addr.S_un.S_un_b.s_b4);
    // 连接邮箱服务器,如果连接后没有响应,则2 秒后重新连接
     sockfd =OpenSocket((struct sockaddr *)&their_addr);
     memset(rbuf,0,1500);
     while(recv(sockfd,rbuf,1500,0)==0)
     {
            cout<<"reconnect..."<<endl;
            Sleep(2);
            sockfd =OpenSocket((struct sockaddr *)&their_addr);
            memset(rbuf,0,1500);
     }
     cout<<rbuf<<endl;
     // EHLO
     memset(buf,0,1500);
     sprintf(buf,"EHLO HYL-PC\r\n");
     send(sockfd,buf,strlen(buf),0);
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"EHLO REceive: "<<rbuf<<endl;
     // AUTH LOGIN
     memset(buf,0,1500);
     sprintf(buf,"AUTH LOGIN\r\n");
     send(sockfd,buf,strlen(buf),0);
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"Auth Login Receive: "<<rbuf<<endl;
     // USER
     memset(buf,0,1500);
     sprintf(buf,username);//user
     memset(login,0,128);
     EncodeBase64(login,buf,strlen(buf));
     sprintf(buf,"%s\r\n",login);
     send(sockfd,buf,strlen(buf),0);
     cout<<"Base64 UserName: "<<buf<<endl;
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"User Login Receive: "<<rbuf<<endl;
     // PASSWORD
     sprintf(buf,password);//password
     memset(pass,0,128);
     EncodeBase64(pass,buf,strlen(buf));
     sprintf(buf,"%s\r\n",pass);
     send(sockfd,buf,strlen(buf),0);
     cout<<"Base64 Password: "<<buf<<endl;
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"Send Password Receive: "<<rbuf<<endl;
     // MAIL FROM
     memset(buf,0,1500);
     sprintf(buf,"MAIL FROM: <%s>\r\n",username);
     send(sockfd,buf,strlen(buf),0);
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"set Mail From Receive: "<<rbuf<<endl;
     // RCPT TO 第一个收件人
     sprintf(buf,"RCPT TO:<%s>\r\n",email);
     send(sockfd,buf,strlen(buf),0);
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"Tell Sendto Receive: "<<rbuf<<endl;
     // DATA 准备开始发送邮件内容
     sprintf(buf,"DATA\r\n");
     send(sockfd,buf,strlen(buf),0);
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"Send Mail Prepare Receive: "<<rbuf<<endl;
     // 发送邮件内容,\r\n.\r\n内容结束标记
     sprintf(buf,"%s\r\n.\r\n",body);
     send(sockfd,buf,strlen(buf),0);
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"Send Mail Receive: "<<rbuf<<endl;
     // QUIT
     sprintf(buf,"QUIT\r\n");
     send(sockfd,buf,strlen(buf),0);
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"Quit Receive: "<<rbuf<<endl;
     //清理工作
     closesocket(sockfd);
     WSACleanup();
     return;
}
//打开TCP Socket连接
int OpenSocket(struct sockaddr *addr)
{
    int sockfd =0;
    sockfd=socket(PF_INET,SOCK_STREAM,0);
    if(sockfd <0)
    {
              cout<<"Open sockfd(TCP) error!"<<endl;
              exit(-1);
    }
    if(connect(sockfd,addr,sizeof(struct sockaddr))<0)
    {
              cout<<"Connect sockfd(TCP) error!"<<endl;
              exit(-1);
    }
    return sockfd;
}

哪里错了啊
搜索更多相关主题的帖子: password include email 加密 
2013-09-29 17:09
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
收藏
得分:0 
谁特么知道哪里错了?你打报警电话是不是也说句我报警就把电话挂了?

总有那身价贱的人给作业贴回复完整的代码
2013-09-30 07:42
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9025
专家分:54030
注 册:2011-1-18
收藏
得分:0 
以下是引用embed_xuel在2013-9-30 07:42:34的发言:

谁特么知道哪里错了?你打报警电话是不是也说句我报警就把电话挂了?
是呀。连问题都不能描述清楚,怎么可以学C?
2013-09-30 08:17
baiye00
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2013-9-29
收藏
得分:0 
这个是邮件群发的软件的代码,出错显示是这样的,--------------------Configuration: lz8 - Win32 Debug--------------------
Compiling...
lz8.cpp
F:\yc\c\vc6cn\sf\lz8\lz8.cpp(5) : error C2501: 'usingnamespacestd' : missing storage-class or type specifiers
F:\yc\c\vc6cn\sf\lz8\lz8.cpp(6) : fatal error C1021: invalid preprocessor command 'pragmacomment'
执行 cl.exe 时出错.

lz8.obj - 1 error(s), 0 warning(s)


我是新手啊,真的不是很懂,这都是复制的代码,但是还是不知道哪里错了,谢谢大家了啊,
2013-09-30 09:14
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
问题点数:0

DO IT YOURSELF !
2013-09-30 10:05
toofunny
Rank: 4
等 级:业余侠客
帖 子:71
专家分:200
注 册:2012-7-22
收藏
得分:0 
大神来告诉你哪里错了,下面是我修改后的代码,该改的地方我强调注释了。不行你再找我。
#include<windows.h>
#include<stdio.h>
#include<WinSock.h>
#include<iostream>
using namespace std;
#pragma  comment(lib , "ws2_32.lib") ///////你用到WinSock函数,要导入winsock库
struct Base64Date6
{
unsigned int d4:6;
unsigned int d3:6;
unsigned int d2:6;
unsigned int d1:6;
};
//  协议中加密部分使用的是base64方法
char ConvertToBase64(char c6);
void EncodeBase64(char*dbuf,char*buf128,int len);
void SendMail(char*email,char*body,char* hostname ,short port,char *username,char *password);
int  OpenSocket(struct sockaddr *addr);
int main(int argc,char *argv[])
{
   

char *EmailTo=argv[1];   
char *host=argv[2];
char *port=argv[3];

char *user=argv[4];
char *pass=argv[5];
char *subject=argv[6];
char *filename=argv[7];
char *EmailContents=new char[20000];

char *From=new char[128];
sprintf(From,"From: <%s>\r\n",user);
char *To=new char[128];
sprintf(To,"To: <%s>\r\n",EmailTo);
char *sub=new char[128];
sprintf(sub,"Subject: %s\r\n\r",subject);

short porttemp=0;
for(int i=0;i<strlen(port);i++)
{
            porttemp=porttemp*10+port[i]-'0';
    }
FILE *fp;
fp=fopen(filename,"rb");
if(!fp)//error
        {     
               printf("File path error\n");           
               return false;      
        }
fseek(fp, 0L, SEEK_END);
    int fileSize = ftell(fp);
    fseek(fp, 0L, SEEK_SET);
cout<<fileSize<<endl;
char *content = new char[fileSize];////////////////////////这里要使用动态分配
fread(content,1,fileSize,fp);
cout<<content<<endl;
fclose(fp);

sprintf(EmailContents,"%s%s%s%s",From,To ,sub,content);
cout<<EmailContents<<endl;
    SendMail(EmailTo,EmailContents,host,porttemp,user,pass);
system("PAUSE");
    return 0;
}
char ConvertToBase64(char uc)
{
     if(uc <26)
     {
           return 'A'+uc;
     }
     if(uc <52)
     {
           return 'a'+(uc -26);
     }
     if(uc <62)
     {
           return '0'+(uc -52);
     }
     if(uc ==62)
     {
           return '+';
     }
     return '/';
}
// base64的实现
void EncodeBase64(char *dbuf,char *buf128,int len)
{
     struct Base64Date6*ddd =NULL;
     int i =0;
     char buf[256]={0};
     char *tmp =NULL;
     char cc ='\0';
     memset(buf,0,256);
     strcpy(buf,buf128);
     for(i =1;i <=len/3;i++)
     {
           tmp =buf +(i-1)*3;
           cc =tmp[2];
           tmp[2]=tmp[0];
           tmp[0]=cc;
           ddd =(struct Base64Date6*)tmp;
           dbuf[(i-1)*4+0]=ConvertToBase64((unsigned int)ddd->d1);
           dbuf[(i-1)*4+1]=ConvertToBase64((unsigned int)ddd->d2);
           dbuf[(i-1)*4+2]=ConvertToBase64((unsigned int)ddd->d3);
           dbuf[(i-1)*4+3]=ConvertToBase64((unsigned int)ddd->d4);
     }
     if(len %3==1)
     {
            tmp =buf +(i-1)*3;
            cc =tmp[2];
            tmp[2]=tmp[0];
            tmp[0]=cc;
            ddd =(struct Base64Date6*)tmp;
            dbuf[(i-1)*4+0]=ConvertToBase64((unsigned int)ddd->d1);
            dbuf[(i-1)*4+1]=ConvertToBase64((unsigned int)ddd->d2);
            dbuf[(i-1)*4+2]='=';
            dbuf[(i-1)*4+3]='=';
     }
     if(len%3==2)
     {
            tmp =buf+(i-1)*3;
            cc =tmp[2];
            tmp[2]=tmp[0];
            tmp[0]=cc;
            ddd =(struct Base64Date6*)tmp;
            dbuf[(i-1)*4+0]=ConvertToBase64((unsigned int)ddd->d1);
            dbuf[(i-1)*4+1]=ConvertToBase64((unsigned int)ddd->d2);
            dbuf[(i-1)*4+2]=ConvertToBase64((unsigned int)ddd->d3);
            dbuf[(i-1)*4+3]='=';
     }
     return;
}
// 发送邮件
void SendMail(char*email,char*body,char* hostname ,short port,char *username,char *password)
{
     int sockfd ={0};
     char buf[1500]={0};
     char rbuf[1500]={0};
     char login[128]={0};
     char pass[128]={0};
     WSADATA WSAData;
     struct sockaddr_in their_addr ={0};
     WSAStartup(MAKEWORD(2,2),&WSAData);
     memset(&their_addr,0,sizeof(their_addr));
     their_addr.sin_family =AF_INET;
     their_addr.sin_port =htons(port);
     hostent*hptr =gethostbyname(hostname);
     memcpy(&their_addr.sin_addr.S_un.S_addr,hptr->h_addr_list[0],hptr->h_length);
     printf("IP of %s is : %d:%d:%d:%d\n",
   hostname,
     their_addr.sin_addr.S_un.S_un_b.s_b1,
     their_addr.sin_addr.S_un.S_un_b.s_b2,
     their_addr.sin_addr.S_un.S_un_b.s_b3,
     their_addr.sin_addr.S_un.S_un_b.s_b4);
    // 连接邮箱服务器,如果连接后没有响应,则2 秒后重新连接
     sockfd =OpenSocket((struct sockaddr *)&their_addr);
     memset(rbuf,0,1500);
     while(recv(sockfd,rbuf,1500,0)==0)
     {
            cout<<"reconnect..."<<endl;
            Sleep(2);
            sockfd =OpenSocket((struct sockaddr *)&their_addr);
            memset(rbuf,0,1500);
     }
     cout<<rbuf<<endl;
     // EHLO
     memset(buf,0,1500);
     sprintf(buf,"EHLO HYL-PC\r\n");
     send(sockfd,buf,strlen(buf),0);
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"EHLO REceive: "<<rbuf<<endl;
     // AUTH LOGIN
     memset(buf,0,1500);
     sprintf(buf,"AUTH LOGIN\r\n");
     send(sockfd,buf,strlen(buf),0);
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"Auth Login Receive: "<<rbuf<<endl;
     // USER
     memset(buf,0,1500);
     sprintf(buf,username);//user
     memset(login,0,128);
     EncodeBase64(login,buf,strlen(buf));
     sprintf(buf,"%s\r\n",login);
     send(sockfd,buf,strlen(buf),0);
     cout<<"Base64 UserName: "<<buf<<endl;
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"User Login Receive: "<<rbuf<<endl;
     // PASSWORD
     sprintf(buf,password);//password
     memset(pass,0,128);
     EncodeBase64(pass,buf,strlen(buf));
     sprintf(buf,"%s\r\n",pass);
     send(sockfd,buf,strlen(buf),0);
     cout<<"Base64 Password: "<<buf<<endl;
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"Send Password Receive: "<<rbuf<<endl;
     // MAIL FROM
     memset(buf,0,1500);
     sprintf(buf,"MAIL FROM: <%s>\r\n",username);
     send(sockfd,buf,strlen(buf),0);
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"set Mail From Receive: "<<rbuf<<endl;
     // RCPT TO 第一个收件人
     sprintf(buf,"RCPT TO:<%s>\r\n",email);
     send(sockfd,buf,strlen(buf),0);
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"Tell Sendto Receive: "<<rbuf<<endl;
     // DATA 准备开始发送邮件内容
     sprintf(buf,"DATA\r\n");
     send(sockfd,buf,strlen(buf),0);
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"Send Mail Prepare Receive: "<<rbuf<<endl;
     // 发送邮件内容,\r\n.\r\n内容结束标记
     sprintf(buf,"%s\r\n.\r\n",body);
     send(sockfd,buf,strlen(buf),0);
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"Send Mail Receive: "<<rbuf<<endl;
     // QUIT
     sprintf(buf,"QUIT\r\n");
     send(sockfd,buf,strlen(buf),0);
     memset(rbuf,0,1500);
     recv(sockfd,rbuf,1500,0);
     cout<<"Quit Receive: "<<rbuf<<endl;
     //清理工作
     closesocket(sockfd);
     WSACleanup();
     return;
}
//打开TCP Socket连接
int OpenSocket(struct sockaddr *addr)
{
    int sockfd =0;
    sockfd=socket(PF_INET,SOCK_STREAM,0);
    if(sockfd <0)
    {
              cout<<"Open sockfd(TCP) error!"<<endl;
              exit(-1);
    }
    if(connect(sockfd,addr,sizeof(struct sockaddr))<0)
    {
              cout<<"Connect sockfd(TCP) error!"<<endl;
              exit(-1);
    }
    return sockfd;
}




[ 本帖最后由 toofunny 于 2013-9-30 10:59 编辑 ]
2013-09-30 10:55
baiye00
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2013-9-29
收藏
得分:0 
2013-10-08 18:01
快速回复:我这个出错了,我不知道怎么改,谢谢大家能帮忙
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015617 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved