S
S
Sergey Khlopov2020-02-01 11:36:41
C++ / C#
Sergey Khlopov, 2020-02-01 11:36:41

How to send a message with SSL/TLS encryption in Winsock2?

Hello, tell me please, I use Winsock2to send mail via SMTP server:

sockaddr_in sin = {0};
      SOCKET s = socket(AF_INET, SOCK_STREAM, 0);
      sin.sin_family = AF_INET;
      sin.sin_port = htons(25);
      sin.sin_addr.s_addr = inet_addr("77.88.21.158");
      int err = connect(s, (sockaddr*)& sin, sizeof(sin));
      char buff[4096];
      memset(buff, '\0', sizeof(buff));
      if (SOCKET_ERROR != err)
      {
        const char* msg[] = {
          "EHLO yandex.ru\r\n",
          "AUTH LOGIN\r\n",
          "login\r\n", // Тут указываю логин от почты в base64
          "pass\r\n", // Тут пароль в base64
          "MAIL FROM:<[email protected]>\r\n",
          "RCPT TO:<[email protected]>\r\n",
          "DATA\r\n",
          "Subject:hello\r\n",
          "Hellow world gacpada \r\n\n.\r\n",
          "CRLF.CRLF\r\n",
          "QUIT\r\n"
        };
        for (int i = 0; i < 10; ++i)
        {
          send(s, msg[i], strlen(msg[i]), 0);
          memset(buff, '\0', 4096);
          recv(s, buff, 4096, 0);
          MessageBoxA(NULL, buff, "Окно", MB_OK);
        }
      }
      closesocket(s);
      break;

When sending in a loop through the send function, on the second iteration of the loop I get the following message:
5e3537c74024d385415571.png
email sending without ssl/tls encryption is not allowed

Can you please tell me how to send a message with SSL / TLS encryption? Thank you in advance for your response.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2020-02-01
@Shlop

Use openssl or similar libraries.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question