email verschicken über smtp
-
Genau! Und wenn du schon mal dabei bist/warst: nirsaja@web.de
-
ist unterwegs...
-
@Surfman
Kannst du mir das Prog. bitte auch schicken? BennyVorwalder@web.de
-
ok ich schicke;-) comments erwünscht;-)
-
bei so vielen nachfragen poste ich den code :
#include <windows.h> #include <winsock.h> #pragma comment (lib, "wsock32.lib") #define HELO_MAX 4 BOOL fHeloSenden (SOCKET) ; BOOL fBodySenden (SOCKET) ; BOOL fQuitSenden (SOCKET) ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){ struct sockaddr_in server ; SOCKET sock ; char command[200], buff[100], szHost[] = "mail.gmx.net" ; unsigned int iFor, iEmpfangen ; short wVersionRequested ; WSADATA wsaData ; struct hostent *he ; ZeroMemory (&server, sizeof (sockaddr_in)) ; wVersionRequested = MAKEWORD (1, 1) ; WSAStartup (wVersionRequested, &wsaData) ; if (!(he = gethostbyname (szHost))){ MessageBox (NULL, "gethostbyname", "Fehler", NULL) ; return 1 ; } if (he->h_addrtype != AF_INET){ MessageBox (NULL, "AF_INET", "Fehler", NULL) ; return 2 ; } if (!he->h_addr_list[0]){ MessageBox (NULL, "he->h_addr_list[0]", "Fehler", NULL) ; return 3 ; } server.sin_family = AF_INET ; server.sin_port = htons (25) ; server.sin_addr = *(struct in_addr*) he->h_addr_list[0] ; if ((sock = socket (PF_INET, SOCK_STREAM, 0)) == -1){ MessageBox (NULL, "socket", "Fehler", NULL) ; return 4 ; } if (connect (sock, (struct sockaddr*) &server, sizeof (struct sockaddr)) < 0){ MessageBox (NULL, "connect", "Fehler", NULL) ; return 5 ; } fHeloSenden (sock) ; fBodySenden (sock) ; fQuitSenden (sock) ; closesocket (sock) ; WSACleanup () ; return 0 ; } BOOL fHeloSenden (SOCKET sock){ char *smtp[] = { "HELO tescik\r\n", "MAIL FROM: <email@email.de>\r\n", "RCPT TO: <email@email.de>\r\n", "DATA\r\n", "From: ich\r\nTo: ich\r\nSubject: Test\r\n"} ; char command[100], buff[100] ; unsigned int iEmpfangen = 0, iFor = 0 ; for(iFor = 0; iFor <= HELO_MAX; iFor++){ strcpy (command, smtp[iFor]) ; send (sock, command, lstrlen (command), 0) ; if (iFor != HELO_MAX){ iEmpfangen = recv (sock, buff, sizeof (buff), 0) ; buff[iEmpfangen] = '\0' ; MessageBox (NULL, (LPTSTR) buff, "empfang", NULL) ; } } return 0 ; } BOOL fBodySenden (SOCKET sock){ char *smtp[] = { "Mime-Version: 1.0\r\n", "Content-Type: multipart/mixed; boundary=\"IstEineID\"\r\n\r\n", "--IstEineID\r\n", "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n", "Content-Transfer-Encoding: 7bit\r\n\r\n", "Teil 1 der email\r\n", "--IstEineID\r\n", "Content-Type: text/plain; charset=\"US-ASCII\"\r\n\r\n", "Teil 2 der email (so zu sagen anhang... hehehe)\r\n", "--IstEineID--"} ; char command[100], buff[100] ; unsigned int iEmpfangen = 0, iFor = 0 ; for(iFor = 0; iFor <= 9; iFor++){ strcpy (command, smtp[iFor]) ; send (sock, command, lstrlen (command), 0) ; } return 0 ; } BOOL fQuitSenden (SOCKET sock){ char *smtp[] = { "\r\n.\r\n", "QUIT\r\n", "QUIT\r\n"} ; char command[100], buff[100] ; unsigned int iEmpfangen = 0, iFor = 0 ; for(iFor = 0; iFor <= 2; iFor++){ strcpy (command, smtp[iFor]) ; send (sock, command, lstrlen (command), 0) ; iEmpfangen = recv (sock, buff, sizeof (buff), 0) ; buff[iEmpfangen] = '\0' ; MessageBox (NULL, (LPTSTR)buff, "empfang", NULL) ; } return 0 ; }
mfg
toom