Ping is not working. Telnet is not an option, sending a mail also. Preferably a function from a library that returns true or false.
Thanks.
Ping is not working. Telnet is not an option, sending a mail also. Preferably a function from a library that returns true or false.
Thanks.
If by working you mean open, you can just connect to the port and see if the socket opens successfully.
If you mean that it's accepting valid SMTP over SSL, then you'd need a library that connects and issues a trivial SMTP command like HELO or something.
Chilkat has library code and examples for this.
Example connect code for win32:
#include <winsock2.h>
#include <ws2tcpip.h>
#include <wspiapi.h>
void tryconnect(const char * host, const char * port)
{
SOCKET Socket = INVALID_SOCKET;
struct addrinfo *resAddrInfo = NULL;
struct addrinfo *ptr = NULL;
struct addrinfo hints;
int result = 0;
printf("Connecting to %s:%s\n", host, port);
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
result = getaddrinfo(host, port, &hints, &resAddrInfo);
if (result != 0)
{
printError("getaddrinfo failed");
return;
}
ptr = resAddrInfo;
Socket = WSASocket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol, NULL, 0, WSA_FLAG_OVERLAPPED);
if (Socket == INVALID_SOCKET)
{
printError("Error Creating Socket");
freeaddrinfo(resAddrInfo);
return;
}
result = WSAConnect(Socket, ptr->ai_addr, (int)ptr->ai_addrlen, NULL, NULL, NULL, NULL);
if (result != 0)
{
printError("Error Connecting");
closesocket(Socket);
freeaddrinfo(resAddrInfo);
return;
}
freeaddrinfo(resAddrInfo);
printf("Success!\n\n");
}
Just make an SSL connection to the SMTP server and attempt to read a line from the stream. The server should send a greeting message as soon as you establish a connection like "220 smtp.domain.com"