Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've written SMTP e-mail sending code using COM-CDO (on Windows); for getting email (POP3) I condensed the following code snippet as a watered-down example. If your POP3 server uses TLS/SSL, your hosed without 3rd-party software - you have to implement SSL and the code would probably take years to develop. I second the use of POCO. Here's what I have for non-SSL (sorry for any Z DIrectory calls, it should be easy to figure out):</p> <pre><code>#include &lt;winsock2.h&gt; #define MAX_MSG 40000 // max message length #define COMM_SUFF "\r\n" #define COMM_USER "USER " #define COMM_PASS "PASS " #define COMM_STAT "STAT\r\n" #define COMM_LIST "LIST\r\n" #define COMM_QUIT "QUIT\r\n" #define COMM_RETR "RETR " #define COMM_TOP "TOP " #define COMM_DELETE "DELE " #define COMM_NOOP "NOOP\r\n" SOCKET sock_no; // SOCKET no struct sockaddr_in sok = {0}; // SOCKET struct struct hostent *hp; string_o command, s, msg_num; string_o user = "EMAIL_USERNAME"; string_o passw = "EMAIL_PASSWORD"; char buff[MAX_MSG]; // pop-3 output buffer sock_no = socket (AF_INET, SOCK_STREAM, 0); // init socket sok.sin_family = AF_INET; int n_bytes = 0; // num of return bytes s = "gorth@Vettrasoft.com"; hp = gethostbyname(s.data()); // get server IP address if (hp != NULL) bcopy ((u_char *) &amp;sok.sin_addr, (const u_char *) hp-&gt;h_addr, hp-&gt;h_length); else return -1; sok.sin_port = (unsigned short int) htons(110); //.......................................................... // connect to pop-3 server and logon //.......................................................... if (::connect(sock_no, (sockaddr *) &amp;sok, sizeof (sockaddr_in)) != 0) return -1; n_bytes = ::recv (sock_no, buff, MAX_MSG, 0); // skip first server answer // send "user" command command = COMM_USER + user + COMM_SUFF; n_bytes = ::send (sock_no, command.data(), command.size(), 0); // get server answer n_bytes = ::recv (sock_no, buff, MAX_MSG, 0); // send PASS command command = COMM_PASS + passw + COMM_SUFF; n_bytes = ::send (sock_no, command.data(), command.size(), 0); n_bytes = ::recv (sock_no, buff, MAX_MSG, 0); // get server answer //.......................................................... // get list of messages; get number of messages in inbox //.......................................................... command = COMM_STAT; n_bytes = ::send (sock_no, command.data(), command.size(), 0); n_bytes = ::recv (sock_no, buff, MAX_MSG, 0); // extract number of messages msg_num = get_field(buff, "+OK "); pos = msg_num.find(' ', &amp;ie); msg_num = msg_num.substring(0, pos); count = ::z_str_to_int (msg_num.data()); //.......................................................... // do all messages from list. # of messages begins from 1 //.......................................................... for (i = 1; i &lt;= count &amp;&amp; !ie; i++) ie = process_nextmail (sock_no, i, buff, do_kill); //.......................................................... // quit and disconnect pop-3 server; send "QUIT" command //.......................................................... command = COMM_QUIT; n_bytes = ::send (sock_no, command.data(), command.size(), 0); return ::closesocket(sock_no); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload