I've been struggling trying to send mime-type email using the libcurl and mod_harbour, but finally made it!
*in this case I'm sending it from a gmail account
here it is:
Código: Seleccionar todo
FUNCTION sendSmtp(wto, wfrom, wpsw)
LOCAL hCurl,uValue,nHandle,cTxt:=""
curl_global_init()
if ! empty( hCurl := curl_easy_init() )
cTxt:="From: Email Test <"+wfrom+">"+Chr(13)+Chr(10)+;
"To: Somebody <"+Alltrim(wto)+">"+Chr(13)+Chr(10)+;
"Subject: Sending email"+Chr(13)+Chr(10)+;
"Date: Tue, 3 Feb 2021 20:40:16"+Chr(13)+Chr(10)+Chr(13)+Chr(10)+;
"Hey, "+Chr(13)+Chr(10)+Chr(13)+Chr(10)+;
"This is a test!"
nHandle := Fcreate("C:\xampp\htdocs\example\tmp\test.txt")
Fwrite(nHandle,cTxt )
FClose(nHandle)
curl_easy_setopt( hCurl, HB_CURLOPT_USE_SSL, HB_CURLUSESSL_TRY )
curl_easy_setopt( hCurl, HB_CURLOPT_UPLOAD )
curl_easy_setopt(hCurl, HB_CURLOPT_USERNAME, wfrom)
curl_easy_setopt(hCurl, HB_CURLOPT_PASSWORD, wpsw)
curl_easy_setopt(hCurl, HB_CURLOPT_URL, "smtps://smtp.gmail.com:465")
curl_easy_setopt( hCurl, HB_CURLOPT_PROTOCOLS, hb_bitOr( HB_CURLPROTO_SMTPS, HB_CURLPROTO_SMTP ) )
curl_easy_setopt( hCurl, HB_CURLOPT_TIMEOUT_MS, 15000 )
curl_easy_setopt(hCurl, HB_CURLOPT_FOLLOWLOCATION, 1)
curl_easy_setopt(hCurl, HB_CURLOPT_SSL_VERIFYPEER, 0)
curl_easy_setopt(hCurl, HB_CURLOPT_MAIL_FROM, wfrom)
curl_easy_setopt(hCurl, HB_CURLOPT_MAIL_RCPT, {wto})
curl_easy_setopt(hCurl, HB_CURLOPT_VERBOSE, 0)
curl_easy_setopt(hCurl, HB_CURLOPT_UPLOAD, 1)
curl_easy_setopt( hCurl, HB_CURLOPT_UL_FILE_SETUP, "C:\xampp\htdocs\example\tmp\test.txt" )
IF (nret:=curl_easy_perform( hCurl )) == 0
uValue := nret
ELSE
uValue:=nret
ENDIF
ENDIF
curl_global_cleanup()
RETURN uValue