今天做了一个简单的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()
{