linux下用C编写的基于smtp的带附件邮件发送程序

         今天做了一个简单的stmp邮件发送的客户端demo,可以支持带附件发送,希望将实现分享一下, 目前测试环境是公司的内部邮箱, 

有gmail邮箱测试没有成功, 可能gmail邮箱需要ssl加密,后续再进行完善吧, 这个demo实现的非常简单的阻塞的发送发送邮件, 在后续的工作中需要

改成非阻塞的方式, 原理就是这样的。 你可以在网上stmp的原理,网上资料很多,在这里就不罗嗦了,本人水平有限, 如有问题,大家可以相互交流,共同

进步。


下面是源码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
#include <unistd.h>
#include <sys/time.h>
#include <netdb.h>


#define TEST_IMG     ("test.jpg")
static char base64_table[64] =
{
	'A', 'B', 'C', 'D', 'E', 'F', 'G',
	'H', 'I', 'J', 'K', 'L', 'M', 'N',
	'O', 'P', 'Q', 'R', 'S', 'T',
	'U', 'V', 'W', 'X', 'Y', 'Z',
	'a', 'b', 'c', 'd', 'e', 'f', 'g',
	'h', 'i', 'j', 'k', 'l', 'm', 'n',
	'o', 'p', 'q', 'r', 's', 't',
	'u', 'v', 'w', 'x', 'y', 'z',
	'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
	'+', '/'
};


int base64_encode(unsigned char *buf, int nLen, char *pOutBuf, int nBufSize);

void sendemail(char *stmpServer, char *body);
int open_socket(struct sockaddr *addr);

int main()
{
 
  • 5
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值