La librería libcurl se pude descargar aquí: http://curl.haxx.se/libcurl/
Para gmail lo mejor es descargar la versión para windows con SSL:
http://www.gknw.net/...vel-mingw32.zip
Dentro del archivo zip se encuentra una carpeta "bin" con todas las dll necesarias, hay que copiarlas en el mismo directorio de nuestra aplicación.
Para manejar la librería he creado esta pequeña unit con algunas funciones básicas:
unit ucurl; interface type TCURL = Pointer; PCURL = ^TCURL; CURLcode = ( CURLE_OK = 0, CURLE_UNSUPPORTED_PROTOCOL, CURLE_FAILED_INIT, CURLE_URL_MALFORMAT, CURLE_OBSOLETE4, CURLE_COULDNT_RESOLVE_PROXY, CURLE_COULDNT_RESOLVE_HOST, CURLE_COULDNT_CONNECT, CURLE_FTP_WEIRD_SERVER_REPLY, CURLE_REMOTE_ACCESS_DENIED, CURLE_OBSOLETE10, CURLE_FTP_WEIRD_PASS_REPLY, CURLE_OBSOLETE12, CURLE_FTP_WEIRD_PASV_REPLY, CURLE_FTP_WEIRD_227_FORMAT, CURLE_FTP_CANT_GET_HOST, CURLE_OBSOLETE16, CURLE_FTP_COULDNT_SET_TYPE, CURLE_PARTIAL_FILE, CURLE_FTP_COULDNT_RETR_FILE, CURLE_OBSOLETE20, CURLE_QUOTE_ERROR, CURLE_HTTP_RETURNED_ERROR, CURLE_WRITE_ERROR, CURLE_OBSOLETE24, CURLE_UPLOAD_FAILED, CURLE_READ_ERROR, CURLE_OUT_OF_MEMORY, CURLE_OPERATION_TIMEDOUT, CURLE_OBSOLETE29, CURLE_FTP_PORT_FAILED, CURLE_FTP_COULDNT_USE_REST, CURLE_OBSOLETE32, CURLE_RANGE_ERROR, CURLE_HTTP_POST_ERROR, CURLE_SSL_CONNECT_ERROR, CURLE_BAD_DOWNLOAD_RESUME, CURLE_FILE_COULDNT_READ_FILE, CURLE_LDAP_CANNOT_BIND, CURLE_LDAP_SEARCH_FAILED, CURLE_OBSOLETE40, CURLE_FUNCTION_NOT_FOUND, CURLE_ABORTED_BY_CALLBACK, CURLE_BAD_FUNCTION_ARGUMENT, CURLE_OBSOLETE44, CURLE_INTERFACE_FAILED, CURLE_OBSOLETE46, CURLE_TOO_MANY_REDIRECTS , CURLE_UNKNOWN_TELNET_OPTION, CURLE_TELNET_OPTION_SYNTAX , CURLE_OBSOLETE50, CURLE_PEER_FAILED_VERIFICATION, CURLE_GOT_NOTHING, CURLE_SSL_ENGINE_NOTFOUND, CURLE_SSL_ENGINE_SETFAILED, CURLE_SEND_ERROR, CURLE_RECV_ERROR, CURLE_OBSOLETE57, CURLE_SSL_CERTPROBLEM, CURLE_SSL_CIPHER, CURLE_SSL_CACERT, CURLE_BAD_CONTENT_ENCODING, CURLE_LDAP_INVALID_URL, CURLE_FILESIZE_EXCEEDED, CURLE_USE_SSL_FAILED, CURLE_SEND_FAIL_REWIND, CURLE_SSL_ENGINE_INITFAILED, CURLE_LOGIN_DENIED, CURLE_TFTP_NOTFOUND, CURLE_TFTP_PERM, CURLE_REMOTE_DISK_FULL, CURLE_TFTP_ILLEGAL, CURLE_TFTP_UNKNOWNID, CURLE_REMOTE_FILE_EXISTS, CURLE_TFTP_NOSUCHUSER, CURLE_CONV_FAILED, CURLE_CONV_REQD, CURLE_SSL_CACERT_BADFILE, CURLE_REMOTE_FILE_NOT_FOUND, CURLE_SSH, CURLE_SSL_SHUTDOWN_FAILED, CURLE_AGAIN, CURLE_SSL_CRL_BADFILE, CURLE_SSL_ISSUER_ERROR, CURLE_FTP_PRET_FAILED, CURLE_RTSP_CSEQ_ERROR, CURLE_RTSP_SESSION_ERROR, CURLE_FTP_BAD_FILE_LIST, CURLE_CHUNK_FAILED, CURL_LAST ); CURLoption = ( CURLOPT_FILE = $2711, CURLOPT_URL = $2712, CURLOPT_PORT = $0003, CURLOPT_PROXY = $2714, CURLOPT_USERPWD = $2715, CURLOPT_PROXYUSERPWD = $2716, CURLOPT_RANGE = $2717, CURLOPT_INFILE = $2719, CURLOPT_ERRORBUFFER = $271A, CURLOPT_WRITEFUNCTION = $4E2B, CURLOPT_READFUNCTION = $4E2C, CURLOPT_TIMEOUT = $000D, CURLOPT_INFILESIZE = $000E, CURLOPT_POSTFIELDS = $271F, CURLOPT_REFERER = $2720, CURLOPT_FTPPORT = $2721, CURLOPT_USERAGENT = $2722, CURLOPT_LOW_SPEED_LIMIT = $0013, CURLOPT_LOW_SPEED_TIME = $0014, CURLOPT_RESUME_FROM = $0015, CURLOPT_COOKIE = $2726, CURLOPT_HTTPHEADER = $2727, CURLOPT_HTTPPOST = $2728, CURLOPT_SSLCERT = $2729, CURLOPT_KEYPASSWD = $272A, CURLOPT_CRLF = $001B, CURLOPT_QUOTE = $272C, CURLOPT_WRITEHEADER = $272D, CURLOPT_COOKIEFILE = $272F, CURLOPT_SSLVERSION = $0020, CURLOPT_TIMECONDITION = $0021, CURLOPT_TIMEVALUE = $0022, CURLOPT_CUSTOMREQUEST = $2734, CURLOPT_STDERR = $2735, CURLOPT_POSTQUOTE = $2737, CURLOPT_WRITEINFO = $2738, CURLOPT_VERBOSE = $0029, CURLOPT_HEADER = $002A, CURLOPT_NOPROGRESS = $002B, CURLOPT_NOBODY = $002C, CURLOPT_FAILONERROR = $002D, CURLOPT_UPLOAD = $002E, CURLOPT_POST = $002F, CURLOPT_DIRLISTONLY = $0030, CURLOPT_APPEND = $0032, CURLOPT_NETRC = $0033, CURLOPT_FOLLOWLOCATION = $0034, CURLOPT_TRANSFERTEXT = $0035, CURLOPT_PUT = $0036, CURLOPT_PROGRESSFUNCTION = $4E58, CURLOPT_PROGRESSDATA = $2749, CURLOPT_AUTOREFERER = $003A, CURLOPT_PROXYPORT = $003B, CURLOPT_POSTFIELDSIZE = $003C, CURLOPT_HTTPPROXYTUNNEL = $003D, CURLOPT_INTERFACE = $274E, CURLOPT_KRBLEVEL = $274F, CURLOPT_SSL_VERIFYPEER = $0040, CURLOPT_CAINFO = $2751, CURLOPT_MAXREDIRS = $0044, CURLOPT_FILETIME = $0045, CURLOPT_TELNETOPTIONS = $2756, CURLOPT_MAXCONNECTS = $0047, CURLOPT_CLOSEPOLICY = $0048, CURLOPT_FRESH_CONNECT = $004A, CURLOPT_FORBID_REUSE = $004B, CURLOPT_RANDOM_FILE = $275C, CURLOPT_EGDSOCKET = $275D, CURLOPT_CONNECTTIMEOUT = $004E, CURLOPT_HEADERFUNCTION = $4E6F, CURLOPT_HTTPGET = $0050, CURLOPT_SSL_VERIFYHOST = $0051, CURLOPT_COOKIEJAR = $2762, CURLOPT_SSL_CIPHER_LIST = $2763, CURLOPT_HTTP_VERSION = $0054, CURLOPT_FTP_USE_EPSV = $0055, CURLOPT_SSLCERTTYPE = $2766, CURLOPT_SSLKEY = $2767, CURLOPT_SSLKEYTYPE = $2768, CURLOPT_SSLENGINE = $2769, CURLOPT_SSLENGINE_DEFAULT = $005A, CURLOPT_DNS_USE_GLOBAL_CACHE = $005B, CURLOPT_DNS_CACHE_TIMEOUT = $005C, CURLOPT_PREQUOTE = $276D, CURLOPT_DEBUGFUNCTION = $4E7E, CURLOPT_DEBUGDATA = $276F, CURLOPT_COOKIESESSION = $0060, CURLOPT_CAPATH = $2771, CURLOPT_BUFFERSIZE = $0062, CURLOPT_NOSIGNAL = $0063, CURLOPT_SHARE = $2774, CURLOPT_PROXYTYPE = $0065, CURLOPT_ENCODING = $2776, CURLOPT_PRIVATE = $2777, CURLOPT_HTTP200ALIASES = $2778, CURLOPT_UNRESTRICTED_AUTH = $0069, CURLOPT_FTP_USE_EPRT = $006A, CURLOPT_HTTPAUTH = $006B, CURLOPT_SSL_CTX_FUNCTION = $4E8C, CURLOPT_SSL_CTX_DATA = $277D, CURLOPT_FTP_CREATE_MISSING_DIRS = $006E, CURLOPT_PROXYAUTH = $006F, CURLOPT_FTP_RESPONSE_TIMEOUT = $0070, CURLOPT_IPRESOLVE = $0071, CURLOPT_MAXFILESIZE = $0072, CURLOPT_INFILESIZE_LARGE = $75A3, CURLOPT_RESUME_FROM_LARGE = $75A4, CURLOPT_MAXFILESIZE_LARGE = $75A5, CURLOPT_NETRC_FILE = $2786, CURLOPT_USE_SSL = $0077, CURLOPT_POSTFIELDSIZE_LARGE = $75A8, CURLOPT_TCP_NODELAY = $0079, CURLOPT_FTPSSLAUTH = $0081, CURLOPT_IOCTLFUNCTION = $4EA2, CURLOPT_IOCTLDATA = $2793, CURLOPT_FTP_ACCOUNT = $2796, CURLOPT_COOKIELIST = $2797, CURLOPT_IGNORE_CONTENT_LENGTH = $0088, CURLOPT_FTP_SKIP_PASV_IP = $0089, CURLOPT_FTP_FILEMETHOD = $008A, CURLOPT_LOCALPORT = $008B, CURLOPT_LOCALPORTRANGE = $008C, CURLOPT_CONNECT_ONLY = $008D, CURLOPT_CONV_FROM_NETWORK_FUNCTION = $4EAE, CURLOPT_CONV_TO_NETWORK_FUNCTION = $4EAF, CURLOPT_CONV_FROM_UTF8_FUNCTION = $4EB0, CURLOPT_MAX_SEND_SPEED_LARGE = $75C1, CURLOPT_MAX_RECV_SPEED_LARGE = $75C2, CURLOPT_FTP_ALTERNATIVE_TO_USER = $27A3, CURLOPT_SOCKOPTFUNCTION = $4EB4, CURLOPT_SOCKOPTDATA = $27A5, CURLOPT_SSL_SESSIONID_CACHE = $0096, CURLOPT_SSH_AUTH_TYPES = $0097, CURLOPT_SSH_PUBLIC_KEYFILE = $27A8, CURLOPT_SSH_PRIVATE_KEYFILE = $27A9, CURLOPT_FTP_SSL_CCC = $009A, CURLOPT_TIMEOUT_MS = $009B, CURLOPT_CONNECTTIMEOUT_MS = $009C, CURLOPT_HTTP_TRANSFER_DECODING = $009D, CURLOPT_HTTP_CONTENT_DECODING = $009E, CURLOPT_NEW_FILE_PERMS = $009F, CURLOPT_NEW_DIRECTORY_PERMS = $00A0, CURLOPT_POSTREDIR = $00A1, CURLOPT_SSH_HOST_PUBLIC_KEY_MD5 = $27B2, CURLOPT_OPENSOCKETFUNCTION = $4EC3, CURLOPT_OPENSOCKETDATA = $27B4, CURLOPT_COPYPOSTFIELDS = $27B5, CURLOPT_PROXY_TRANSFER_MODE = $00A6, CURLOPT_SEEKFUNCTION = $4EC7, CURLOPT_SEEKDATA = $27B8, CURLOPT_CRLFILE = $27B9, CURLOPT_ISSUERCERT = $27BA, CURLOPT_ADDRESS_SCOPE = $00AB, CURLOPT_CERTINFO = $00AC, CURLOPT_USERNAME = $27BD, CURLOPT_PASSWORD = $27BE, CURLOPT_PROXYUSERNAME = $27BF, CURLOPT_PROXYPASSWORD = $27C0, CURLOPT_NOPROXY = $27C1, CURLOPT_TFTP_BLKSIZE = $00B2, CURLOPT_SOCKS5_GSSAPI_SERVICE = $27C3, CURLOPT_SOCKS5_GSSAPI_NEC = $00B4, CURLOPT_PROTOCOLS = $00B5, CURLOPT_REDIR_PROTOCOLS = $00B6, CURLOPT_SSH_KNOWNHOSTS = $27C7, CURLOPT_SSH_KEYFUNCTION = $4ED8, CURLOPT_SSH_KEYDATA = $27C9, CURLOPT_MAIL_FROM = $27CA, CURLOPT_MAIL_RCPT = $27CB, CURLOPT_FTP_USE_PRET = $00BC, CURLOPT_RTSP_REQUEST = $00BD, CURLOPT_RTSP_SESSION_ID = $27CE, CURLOPT_RTSP_STREAM_URI = $27CF, CURLOPT_RTSP_TRANSPORT = $27D0, CURLOPT_RTSP_CLIENT_CSEQ = $00C1, CURLOPT_RTSP_SERVER_CSEQ = $00C2, CURLOPT_INTERLEAVEDATA = $27D3, CURLOPT_INTERLEAVEFUNCTION = $4EE4, CURLOPT_WILDCARDMATCH = $00C5, CURLOPT_CHUNK_BGN_FUNCTION = $4EE6, CURLOPT_CHUNK_END_FUNCTION = $4EE7, CURLOPT_FNMATCH_FUNCTION = $4EE8, CURLOPT_CHUNK_DATA = $27D9, CURLOPT_FNMATCH_DATA = $27DA, CURLOPT_RESOLVE = $27DB, CURLOPT_TLSAUTH_USERNAME = $27DC, CURLOPT_TLSAUTH_PASSWORD = $27DD, CURLOPT_TLSAUTH_TYPE = $27DE ); curl_usessl = ( CURLUSESSL_NONE = 0, CURLUSESSL_TRY, CURLUSESSL_CONTROL, CURLUSESSL_ALL, CURLUSESSL_LAST ); pcurl_slist = ^curl_slist; curl_slist = record data: PAnsiChar; next: ^pcurl_slist; end; const libcurl = 'libcurl.dll'; CURL_GLOBAL_SSL = 1; CURL_GLOBAL_WIN32 = 2; CURL_GLOBAL_ALL = CURL_GLOBAL_SSL or CURL_GLOBAL_WIN32; CURL_GLOBAL_NOTHING = 0; CURL_GLOBAL_DEFAULT = CURL_GLOBAL_ALL; // easy interface function curl_easy_init: TCURL; cdecl; external libcurl; function curl_easy_setopt(curl: TCURL; option: CURLoption): CURLcode; cdecl; varargs; external libcurl; function curl_easy_perform(curl: TCURL): CURLcode; cdecl; external libcurl; procedure curl_easy_cleanup(curl: TCURL); cdecl; external libcurl; // initialization function curl_global_init(flags: Longint): CURLcode; cdecl; external libcurl; procedure curl_global_cleanup; cdecl; external libcurl; // curl_slist function curl_slist_append(list: pcurl_slist; const Str: PAnsiChar): pcurl_slist; cdecl; external libcurl; procedure curl_slist_free_all(list: pcurl_slist); cdecl; external libcurl; implementation initialization curl_global_init(CURL_GLOBAL_ALL); finalization curl_global_cleanup; end.
Y aqui esta el código para enviar el correo:
function ReadFromStream(Buffer: PAnsiChar; Size, Count: Integer; Stream: TStream): Integer; cdecl; begin Result:= Stream.Read(Buffer^,Size*Count) div Size; end; function EnviarMail(Usuario, Clave, De, Para, Asunto, Texto: AnsiString): Boolean; var Curl: TCURL; Rcpt: pcurl_slist; Stream: TMemoryStream; begin Result:= FALSE; Curl:= curl_easy_init; if Curl <> nil then try // Queremos que se muestre informacion sobre todo el proceso if curl_easy_setopt(Curl, CURLOPT_VERBOSE, TRUE) <> CURLE_OK then Exit; // Queremos usar SSL if curl_easy_setopt(Curl, CURLOPT_USE_SSL, CURLUSESSL_ALL) <> CURLE_OK then Exit; // No queremos que compruebe el certificado de gmail if curl_easy_setopt(Curl, CURLOPT_SSL_VERIFYPEER, FALSE) <> CURLE_OK then Exit; // Nombre de usuario if curl_easy_setopt(Curl, CURLOPT_USERNAME, PAnsiChar(Usuario)) <> CURLE_OK then Exit; // Clave if curl_easy_setopt(Curl, CURLOPT_PASSWORD, PAnsiChar(Clave)) <> CURLE_OK then Exit; // URL de gmail if curl_easy_setopt(Curl, CURLOPT_URL, PChar('smtps://smtp.gmail.com')) <> CURLE_OK then Exit; if curl_easy_setopt(Curl, CURLOPT_MAIL_FROM, PAnsiChar(De)) <> CURLE_OK then Exit; Rcpt:= nil; // Creamos una lista con los receptores Rcpt:= curl_slist_append(Rcpt,PAnsiChar(Para)); // Podemos repetir la linea anterior para añadir mas de un receptor try if curl_easy_setopt(Curl, CURLOPT_MAIL_RCPT, Rcpt) <> CURLE_OK then Exit; // Le indicamos que tiene que usar la funcion ReadFromStream para leer el contenido del mensaje if curl_easy_setopt(Curl, CURLOPT_READFUNCTION, @ReadFromStream) <> CURLE_OK then Exit; Stream:= TMemoryStream.Create; try // Creamos el contenido del mensaje y lo guardamos en un stream with TStringList.Create do try Add('Content-Type: text/plain;'); Add('Subject: ' + Asunto); Add('User-Agent: Curl'); Add(EmptyStr); Add(Texto); SaveToStream(Stream); finally Free; end; Stream.Position:= 0; // Le indicamos que debe usar el stream que acabamos de crear if curl_easy_setopt(Curl, CURLOPT_INFILE, Stream) <> CURLE_OK then Exit; if curl_easy_setopt(Curl, CURLOPT_UPLOAD, TRUE) <> CURLE_OK then Exit; // Enviamos el mensaje Result:= curl_easy_perform(Curl) = CURLE_OK; finally Stream.Free; end; finally curl_slist_free_all(Rcpt); end; finally curl_easy_cleanup(Curl); end; end;
Aquí dejo un ejemplo, en un archivo zip, pero hay que copiar las dll de la carpeta "bin" para que funcione.