C语言编写smtp用户代理之代码综合和管理
2017-07-21 19:37
525 查看
前两章已经写好了必要的函数,现在写一个主函数调用就可以了。
这些都有了之后,写一个简单的Makefile。我使能了ssl,所以要加上openssl的库,需要 加上 -lssl 和 -lcrypto
使用如下命令进行测试
测试结果如下
写在后面:
因为中间用了base64的编码,可以你们自己写,也可以用我这里的源码,我也是用的别人的。
请到这个地址下载:
http://download.csdn.net/detail/renyongjian1994/9906868
这里要多说一些,使用qq邮箱,有的人的密码是不能直接用的。需要对邮箱进行设定。进入qq邮箱的网页界面,点击设置,然后到如下位置设置,设置之后可以得到授权码,然后用授权码代替密码,应该就可以使用了。
#include<unistd.h> #include"renyj_sock.h" #include"smtp.h" #include"mutils.h" int main(int argc, char *argv[]) { int opt = -1; char from[100] = ""; char to[100] = ""; char server[100]= ""; char port[5] = ""; char user[100] = ""; char pass[100] = ""; char subject[100]=""; char msgline[100]=""; while (-1 != (opt = getopt(argc,argv,"f:t:s:p:u:m:z:x:h"))) { switch(opt) { case 'f': strncpy(from,optarg,100); if (strlen(from)<=0) { debug("invalid from "); return -1; } break; case 't': strncpy(to,optarg,100); if (strlen(to) <= 0) { debug("invalid to"); return -1; } break; case 's': strncpy(server,optarg,100); if (strlen(server) <= 0) { debug("invalid server"); return -1; } break; case 'p': strncpy(port,optarg,5); if (strlen(port) <= 0) { debug("invalid port"); return -1; } break; case 'u': strncpy(user,optarg,100); if (strlen(user) <= 0) { debug("invalid user"); return -1; } break; case 'm': strncpy(pass,optarg,100); if (strlen(pass) <= 0) { debug("invalid pass"); return -1; } break; case 'z': strncpy(subject,optarg,100); if (strlen(subject) <= 0) { debug("invalid subject"); return -1; } break; case 'x': strncpy(msgline,optarg,100); if (strlen(msgline) <= 0) { debug("need one line"); } break; case '?': printf("unknow option %c\n",optopt); case ':': printf("use -h for help\n"); return -1; case 'h': printf("-f mail from\n"); printf("-t mail to\n"); printf("-s mail server\n"); printf("-p mail serverport\n"); printf("-u mail user\n"); printf("-m mail pass\n"); printf("-z mail subject\n"); printf("-x mail one line msg\n"); printf("All info should be less than 100 bytes,port should less than 5!!!\n"); return -1; } } send_the_mail(from,to,server,atoi(port),user,pass,subject,msgline,10); return 0; }
这些都有了之后,写一个简单的Makefile。我使能了ssl,所以要加上openssl的库,需要 加上 -lssl 和 -lcrypto
obj = renyj_sock.c smtp.c test.c CC = gcc MUTILIB=./libmutils/libmutils.a LIBS= $(MUTILIB) -lssl -lcrypto INCLUDE= libmutils CFLAGS= -DDEBUG -DHAS_SSL -g -I$(INCLUDE) link: gcc $(CFLAGS) $(obj) -o sock_test $(LIBS) clean: rm sock_test install: echo "nothing to be done"
使用如下命令进行测试
./sock_test -f xxx@qq.com -t xxx@qq.com -s smtp.qq.com -p 465 -u xxx@qq.com -m xxx -z hello -x 123
测试结果如下
Debug>>>renyj_sock.c->turn_on_ssl()->line.239:connect ... Debug>>>renyj_sock.c->turn_on_ssl()->line.247:connect end Debug>>>smtp.c->smtp_read_line()->line.14:[S] -----> 220 smtp.qq.com Esmtp QQ Mail Server Debug>>>smtp.c->smtp_read_line()->line.14:[S] -----> 250-smtp.qq.com Debug>>>smtp.c->smtp_read_line()->line.14:[S] -----> 250-PIPELINING Debug>>>smtp.c->smtp_read_line()->line.14:[S] -----> 250-SIZE 73400320 Debug>>>smtp.c->smtp_read_line()->line.14:[S] -----> 250-AUTH LOGIN PLAIN Debug>>>smtp.c->smtp_read_line()->line.14:[S] -----> 250-AUTH=LOGIN Debug>>>smtp.c->smtp_read_line()->line.14:[S] -----> 250-MAILCOMPRESS Debug>>>smtp.c->smtp_read_line()->line.14:[S] -----> 250 8BITMIME Debug>>>smtp.c->send_the_mail()->line.167:start AUTH Debug>>>smtp.c->smtp_read_line()->line.14:[S] -----> 334 VXNlcm5hbWU6 Debug>>>smtp.c->smtp_read_line()->line.14:[S] -----> 334 UGFzc3dvcmQ6 Debug>>>smtp.c->smtp_read_line()->line.14:[S] -----> 235 Authentication successful Debug>>>smtp.c->send_the_mail()->line.171:start FROM Debug>>>smtp.c->smtp_read_line()->line.14:[S] -----> 250 Ok Debug>>>smtp.c->send_the_mail()->line.175:start TO Debug>>>smtp.c->smtp_read_line()->line.14:[S] -----> 250 Ok Debug>>>smtp.c->send_the_mail()->line.179:start DATA Debug>>>smtp.c->smtp_read_line()->line.14:[S] -----> 354 End data with <CR><LF>.<CR><LF> Debug>>>smtp.c->send_the_mail()->line.193:start eom Debug>>>smtp.c->smtp_read_line()->line.14:[S] -----> 250 Ok: queued as Debug>>>smtp.c->send_the_mail()->line.197:QUIT Debug>>>smtp.c->smtp_read_line()->line.14:[S] -----> 221 Bye
写在后面:
因为中间用了base64的编码,可以你们自己写,也可以用我这里的源码,我也是用的别人的。
请到这个地址下载:
http://download.csdn.net/detail/renyongjian1994/9906868
这里要多说一些,使用qq邮箱,有的人的密码是不能直接用的。需要对邮箱进行设定。进入qq邮箱的网页界面,点击设置,然后到如下位置设置,设置之后可以得到授权码,然后用授权码代替密码,应该就可以使用了。
相关文章推荐
- 使用C语言编写一个smtp用户代理
- C语言编写smtp用户代理之协议操作
- C语言编写smtp用户代理之socket操作
- C语言编写的学生成绩管理系统代码…
- C语言 编写代码实现,模拟用户登录场景 ( for循环,if语句的使用)
- C语言编写的银行管理系统关键代码
- C语言编写windows用户账户管理
- 编写一个简单的用户管理系统(工厂代理模式)
- linux系统管理客户端2--串口实现测试代码编写
- 浅谈思路严谨的管理软件中的用户在线状态控制【附部分C#参考代码】
- 用c语言代码编写的游戏“简易五子棋”
- 我是这样编写C语言代码的
- SAE 平台代码实现数据库定时备份以及同步到本地 2014/09/11 09:39:01 分类: 技术随笔 1人评论 次浏览 SAE 只允许用户通过phpMyAdmin管理远程数据库,
- 编写代码:ATM的登陆界面(用户验证、主菜单的选择) 查询-- 存款-- 取款-- 退出
- java编写学生成绩管理系统代码
- 七天学会ASP.NET MVC (四)——Layout页面使用和用户角色管理 (代码下载)
- C语言编写代码,演示多个字符从两端移动,向中间汇聚
- 【linux下用C语言编写带图形界面的成绩管理系统附带源代码】
- (一个代码学会c语言操作数据库)linux上通过c语言操作数据库实现基本的学生信息管理系统(增、删、查、改‘显示)
- 我记录综合系统学习研究之用户管理一(wojilu.Web.Controller.Users MainController)