Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

[C++]Wysyłanie maila z załącznikiem


Rekomendowane odpowiedzi

Opublikowano


#include <iostream>

#include <winsock2.h>

#include <conio.h>

 

using namespace std;

 

int main()

{

cout <<"Rozpoczynam wysylanie mail'a z wytycznymi:\r\n";

cout <<"helo <moja_nazwa>"<<'\n'; string helo = "helo <moja_nazwa>\r\n";

cout <<"auth login"<<'\n'; string auth = "auth login\r\n";

cout <<"moj_login"<<'\n'; string login = "moj_login\r\n";

cout <<"moje_haslo"<<'\n'; string haslo = "moje_haslo\r\n";

cout <<"mail from:<[email protected]>"<<'\n'; string from = "mail from:<[email protected]>\r\n";

cout <<"rcpt to:<[email protected]>"<<'\n'; string to = "rcpt to:<[email protected]>\r\n";

cout <<"subject:TEMAT"<<'\n'; string temat = "subject:TEMAT\r\n";

cout <<"data"<<'\n'; string data = "data\r\n";

cout <<"jakas_tam_tresc"<<'\n'; string tresc = "jakas_tam_tresc\r\n";

cout <<"zalacznik"<<'\n'; string zal = "zalacznik\r\n";

cout <<"."<<'\n'; string kropka = ".\r\n";

cout <<"quit"<<'\n'; string koniec = "quit\r\n";

cout <<"Szukam hosta..."<<'\n';

 

WSADATA wsadata;

SOCKET sock;

hostent *host;

 

struct sockaddr_in addr;

 

WSAStartup( 0x101, &wsadata ); // rozpoczynam polaczenie

sock = socket(AF_INET, SOCK_STREAM, 0); // tworze socket

host = gethostbyname("nazwaSerweraSMTP"); // pobieram host'a

addr.sin_family = AF_INET; // wypelniam strukture addr

addr.sin_port = htons(25);

addr.sin_addr.s_addr = *((unsigned long *)host->h_addr);

 

cout <<"Odnaleziono i ustawiono!"<<'\n';

 

if( !connect( sock, (sockaddr*)&addr, sizeof(addr) ) ) // lacze z serwerem

{

char odebrane[2048] = {0};

cout <<"Polaczono!"<<'\n';

cout <<"Wysylam..."<<'\n';

cout <<"Rozmowa z serwerem:\n"<<'\n';

 

send( sock, helo.c_str(), strlen( helo.c_str() ), 0 ); cout << helo << '\n';

recv( sock, odebrane, sizeof(odebrane), 0 ); cout << odebrane << '\n';

 

send( sock, auth.c_str(), strlen( auth.c_str() ), 0 ); cout << auth << '\n';

recv( sock, odebrane, sizeof(odebrane), 0 ); cout << odebrane << '\n';

 

send( sock, (login+haslo).c_str(), strlen( (login+haslo).c_str() ), 0 ); cout << (login+haslo) << '\n';

recv( sock, odebrane, sizeof(odebrane), 0 ); cout << odebrane << '\n';

 

send( sock, from.c_str(), strlen( from.c_str() ), 0 ); cout << from << '\n';

recv( sock, odebrane, sizeof(odebrane), 0 ); cout << odebrane << '\n';

 

send( sock, to.c_str(), strlen( to.c_str() ), 0 ); cout << to << '\n';

recv( sock, odebrane, sizeof(odebrane), 0 ); cout << odebrane << '\n';

 

send( sock, temat.c_str(), strlen( temat.c_str() ), 0 ); cout << temat << '\n';

recv( sock, odebrane, sizeof(odebrane), 0 ); cout << odebrane << '\n';

 

send( sock, data.c_str(), strlen( data.c_str() ), 0 ); cout << data << '\n';

recv( sock, odebrane, sizeof(odebrane), 0 ); cout << odebrane << '\n';

 

send( sock, tresc.c_str(), strlen( tresc.c_str() ), 0 ); cout << tresc << '\n';

recv( sock, odebrane, sizeof(odebrane), 0 ); cout << odebrane << '\n';

 

send( sock, zal.c_str(), strlen( zal.c_str() ), 0 ); cout << zal << '\n';

recv( sock, odebrane, sizeof(odebrane), 0 ); cout << odebrane << '\n';

 

send( sock, kropka.c_str(), strlen( kropka.c_str() ), 0 ); cout << kropka << '\n';

recv( sock, odebrane, sizeof(odebrane), 0 ); cout << odebrane << '\n';

 

send( sock, koniec.c_str(), strlen( koniec.c_str() ), 0 ); cout << koniec << '\n';

recv( sock, odebrane, sizeof(odebrane), 0 ); cout << odebrane << '\n';

 

cout <<"\n\nWyslano!"<<'\n';

WSACleanup(); // zamykam polaczenie i czyszcze po sobie

getch();

return 0;

}

else

{

cout <<"Nie udalo sie polaczyc..."<<'\n';

WSACleanup();

getch();

return 0;

}

}

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...