/ ************************************************** ************ * SMTP.CPP - Use SMTP TO Send An Email with an attachment and verify * * Copyright (c) 2001-2002 by shadowstar. * * Use and modify free. * * Http : //shadowstar.126.com/ ********************************************************** ******************** * / / / ------------------------- --------------------------------------------------
#include
const int BASE64_MAXLINE = 76; const char EOL [] = "/ r / n"; const char BASE64_TAB [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz0123456789 /"; const char HEADER [] = "HELO support.com/r/n" / / "Auth login / r / n" // base64 user base64 pass "mail from: chinansl@support.com/r/n" "rcpt to: shadowstar@support.com/R/N" "DATA / R / n "" from: chinansl@support.com/r/n "" to: shadowstar@support.com/r/n "" Subject: this is a test / r / n "" DATE: 2002-5-14 / R / N "" x-mailer: shadowstar's mailer / r / n "" MIME-VERSION: 1.0 / R / N "" Content-type: multipart / mix; bitchary = / "# boundary # /" / r / n "/ / "Content-Type: Text / Plain; Charset = GB2312 / R / N" "/ r / n"; const char constant [] = "/ r / n - # boundary # / r / n" "Content-Type : Text / Plain; Charset = GB2312 / R / N "" Content-Transfer-Encoding: quoted-printable / r / n "" / r / n "" / ************* *********************************** "" * SMTP.CPP - Use SMTP TO Send An Email with an attachment and verify * "* CopyRight (c) 2001-2002 by ShadowStar. * "*" * "* Http://shadowstar.126.com/ *" "********************** ************************************ "" * // r / n "" / r / n "; const char att_header [] =" / r / n - # boundary # / r / n "" content-type: Application / OCT-stream; Name =
SMTP.EXE / R / N "" Content-disposition: attachment; filename = SMTP.EXE / R / N "" Content-Transfer-Encoding: Base64 / R / N "/ r / n"; // --- -------------------------------------------------- --------------------- Int Ansitobase64 (Const Char * Szinansi, Int Ninlen, Char * SzoutBase64, Int Noutlen);
INT main (int Argc, char * argv [{) {wsadata wsadata; int suckfd; struct sockaddr_in servaddr; char buf [0x100]; int x; file * fp; char * aatt = new char [0x400000]; char * batt = New char [0x555556];
WSASTARTUP (Makeword (2, 2), & WSADATA);
LPHOSTENT pHost = gethostbyname ( "172.16.234.111"); SockFD = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); ServAddr.sin_family = AF_INET; ServAddr.sin_addr.s_addr = * (ULONG *) pHost-> h_addr_list [0]; ServAddr. SIN_PORT = HTONS (25);
Connect (Sockfd, (Struct SockAddr *) & Servaddr, SIZEOF (SIZEOF (SOCKFD, HEADER, STRLEN (HEADER), 0); // Send Content Send (SockFD, Content, Strlen (Content), 0); // send_header send (sockfd, att_header, strlen (att_header), 0); // read attachment fp = fopen (argv [0], "rb"); FSEEK (fp, 0, 2); x = Ftell (fp); if (x> 0x400000) x = 0; ReWind (fp); Fread (AATT, X, 1, FP); fclose (fp); x = ansitobase64 (AATT, X, Batt, 0x555556); / / send base64 attachment Send (sockfd, batt, x, 0);
Send (sockfd, "./r/N", strlen ("./ r / n"), 0); // end send (SOCKFD, "QUIT / R / N", Strlen ("quit / r / n" ), 0); // quit
CloseSocket (SOCKFD); WSACLEANUP ();
Delete [] aatt; delete [] batt; return 0;} // ---------------------------------- ----------------------------------------- int around it* as6 (const char * szinansi, int Ninlen, char * szoutbase64, int noutlen) {// input parameter validation if ((szinansi == null) || (ninlen == 0) || (SzoutBase64 == null) || (NOUTLEN == 0)) Return 0 ; IF (NOUTLEN <(NOUTLEN * 4/3 1 NINLEN * 4/3 / BASE64_MAXLINE * 2 1 4)) Return 0; // set up the parameters prior to the main encoding loop int ninpos = 0; int NOUTPOS = 0; int nlinelen = 0; INT C1, C2, C3; INT I;
// Get Three Characters at a time from the input buffer and encode itm for (i = 0; i // Encode INTO THE 4 6 Bit Characters SzoutBase64 [NOUTPOS ] = Base64_Tab [C1 >> 2]; SzoutBase64 [NOUTPOS ] = Base64_Tab [((C1 << 4) | (C2 >> 4)) & 0x3f]; szoutBase64 [ NOUTPOS ] = Base64_Tab [((C2 << 2) | (C3 >> 6)) & 0x3f]; SzoutBase64 [NOUTPOS ] = base64_tab [c3 & 0x3f]; nLinelen = 4; // Handle The case where we have gone over the max line boundaryiff (nLinelen> Base64_maxline - 4) {szoutbase64 [NOUTPOS ] = EOL [0]; szoutbase64 [NOUTPOS ] = EOL [1]; nLinelen = 0;}} // encode the remaining one or two {ss 0: {szoutbase64 [noutpos ] = eol [0]; szoutbase64 [NOUTPOS ] = Eol [1]; Break;} case 1: {C1 = szinansi [ninpos] & 0xff; szoutbase64 [NOUTPOS ] = base64_tab [(C1 & 0xFC) >> 2]; SzoutBase64 [NOUTPOS ] = Base64_Tab [((C1 & 0x03) << 4)]; szoutbase64 [NOUTPOS ] = '='; Szoutbase64 [NOUTPOS ] = '='; szoutbase64 [NOUTPOS ] = EOL [0]; szoutbase64 [NOUTPOS ] = EOL [1]; Break;} case 2: {c1 = szinansi [ninpos ] & 0xFF; C2 = SZINANSI [NINPOS] & 0xFF; SzoutBase64 [NOUTPOS ] = Base64_Tab [(C1 & 0xFC) >> 2]; SzoutBase64 [NOUTPOS ] = Base64_Tab [((C1 & 0x03) << 4) | ((C2 & 0xF0) >> 4)]; SzoutBase64 [NOUTPOS ] = Base64_Tab [((C2 & 0x0F) << 2)]; szoutbase64 [NOUTPOS ] = '='; szoutbase64 [NOUTPOS ] = EOL [0]; szoutbase64 [NOUTPOS ] = EOL [1]; Break;} default: {return 0;}} szoutbase64 [noutpos] = 0; Return noutpos;