• 大小: 127KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-20
  • 语言: C/C++
  • 标签: 发送邮件  

资源简介

c语言实现的发送邮件

资源截图

代码片段和文件信息

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

static int ZJF_Mail_int2char_FUN(int a)
{
    if(a <= 25)
    {
        return ‘A‘+(a-0);
    }
else if((a > 25)&&(a <= 51))
{
    return ‘a‘+(a-26);
}
else if((a > 51)&&(a < 61))
{
    return ‘0‘+(a-52);
}
else if(a == ‘=‘)
{
    return a;
}
else if(a == 62)
{
    return ‘+‘;
}
else if(a == 63)
{
    return ‘/‘;
}
    return 0;
}

static int ZJF_Mail_LittleToBig_FUN(char *str1int len)
{
    int i    = 0;
    int temp = 0;
    for(i = 0; i < len; i++)
    {
        temp |= (str1[i] << (len-i-1)*8);        
    }
//printf(“%#x \n“temp); 
    return temp;
}

static int ZJF_Mail_base64Encod_FUN(char * datachar *outputint lenint *oputlen)
{

int ijk;
    char strtemp[4] = { 0 };  /*每次拷贝三个字节出来,存储*/
    int temp = 0;
char * pbuffer = (char * )malloc(len/3*4+4);
 
for(i = 0j = 0; i < len/3; i++)
{            
        memcpy(strtempdata+3*i3);    
        temp = ZJF_Mail_LittleToBig_FUN(strtemp3);
                              
pbuffer[j++] = (temp>>18)&0x3f;   //0x3f  111111
pbuffer[j++] = (temp>>12)&0x3f;  
pbuffer[j++] = (temp>>6)&0x3f;   
pbuffer[j++] = (temp>>0)&0x3f;   

if(j == 75)
{
    pbuffer[j++] = ‘\n‘;
}
}
        
if(len%3 == 1)
{
        memcpy(strtempdata+3*i1);
temp = (int)strtemp[0];
    pbuffer[j++] = temp>>2;
    pbuffer[j++] = (temp&0x03)<<4;
    pbuffer[j++] = ‘=‘;
    pbuffer[j++] = ‘=‘;
}
    else if(len%3 == 2)
{
        memcpy(strtempdata+3*i2);
        temp = ZJF_Mail_LittleToBig_FUN(strtemp2);
    pbuffer[j++] = temp>>10;
    pbuffer[j++] = (temp>>4)&0x3f;
    pbuffer[j++] = (temp<<2)&0x3f;
    pbuffer[j++] = ‘=‘;
}
    pbuffer[j++] = ‘\0‘;

for(i = 0;i < j-1;i++)
    {
        //printf(“%c “ZJF_Mail_int2char_FUN(pbuffer[i]));
output[i]= ZJF_Mail_int2char_FUN(pbuffer[i]);
    }
printf(“\n“);
    *oputlen = j-1; 
//printf(“data len = %d \n“j-1);
if(pbuffer != NULL)
{
    free(pbuffer);
pbuffer = NULL;
}

    return 0;

}


#define IP_ADDR      (“smtp.sina.com“)
static ZJF_Mail_GetPeerAddrInfo_FUN(struct sockaddr_in *PeerAddr)
{
    struct hostent *Addr;
char ip[32] = { 0 };

Addr = gethostbyname(IP_ADDR);
if(NULL == Addr)
{
    perror(“err:“);
    printf(“get ip info err !!! \n“);
return -1;
}

    memset(PeerAddr 0 sizeof(struct sockaddr_in));  
    PeerAddr->sin_family = AF_INET;
    PeerAddr->sin_port   = htons(25);

inet_ntop(Addr->h_addrtype Addr->h_addr_list[0] ip sizeof(ip));
PeerAddr->sin_addr.s_addr = inet_addr(ip);
printf(“ip:%s len: %d \n“ipstrlen(ip));

    return 0;
}


static int ZJF_Mail_OpenSocket_FUN(struct sockaddr *addr)
{
    int

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      12607  2016-08-11 10:54  Email\a.out

     文件     167286  2016-08-09 17:28  Email\base64编码对应表.jpg

     文件       8553  2016-08-11 10:56  Email\mail.c

     目录          0  2016-08-11 10:54  Email

----------- ---------  ---------- -----  ----

               188446                    4


评论

共有 条评论