Send Email with LibCurl

i have a trouble with libcurl send email i try with this code and received “Send Failed: Login denied”, but with same credentials work with netttalk(last version), i need a solutions for clarion 6.3 apps, the vuMail 3.5 not work with sendgrid.net return this error “The transport failed to connect to the server” and need another tool compatible with clarion 6.3

     EMailProvider = 'gmail'  
    CASE LOWER(EMailProvider)
    OF 'gmail'        
        curl.Server('smtp.sendgrid.net', 587)
        curl.Account('apikey', 'mypassword')
        curl.From('myfrom')
        curl.AddRecipient('myemail')        
    END     
         
    curl.useSSL(CURL_SSLVERSION_DEFAULT)
    curl.setSSLVerifyPeer(False)
    curl.setSSLVerifyHost(False)
    
    curl.Subject('Test email')
    curl.Body('Test email using libcurl')

    curl.SetOpt(CURLOPT_CONNECTTIMEOUT, 30)

    res = curl.Send()
    IF res = CURLE_OK
        MESSAGE('Email sent', 'SendMail', ICON:Asterisk)
    ELSE
        MESSAGE('Send failed: '& curl.StrError(res), 'SendMail', ICON:Exclamation)
    END

With smtp2go I was able to send emails using curl

Try full server address: smtp://smtp.blabla.com.

I already tried it and it gives the same error

Be sure that the port number is correct. Inspect debugview log.

I’ve tried all available ports with sendgrid and it doesn’t work

This is the code I am using with Clarion 6.3, Sendgrid and LibCurl, it works. Your error looks like an authorisation error??

  curl.Init()
  SendGridApiAccessCode = 'Authorization:Bearer ' & CLIP(SendGridApiAccessCode)
  curl.AddHttpHeader(CLIP(SendGridApiAccessCode))
  curl.AddHttpHeader('Content-Type: application/json')
  curl.AddHttpHeader('Content-Transfer-Encoding:quoted-printable')
  curl.SetHttpHeaders()  ! Got to set em!
  curl.SetCustomRequest('POST')
  curl.SetSSLVerifyHost(false)
  curl.SetSSLVerifyPeer(false)
  curl.SetSSLVersion(CURL_SSLVERSION_DEFAULT)


  Res = curl.SendRequestStr(CLIP(SendGridApiUrl), CLIP(JSONSTRING), respBuffer)

  IF res <> CURLE_OK
    curl.StrError(Res)
  END

  RETURN CLIP(respBuffer)

Thanks for sharing that code. I’m trying to use TCurlMailClass, and that’s the library that’s giving me the error. But with smtp2go and Netttalk, I can make the connection. I’ll look into that solution.

        curl.Server('smtp://smtp.sendgrid.net',587)            
        curl.Account('apikey', 'mykey)                       
        curl.From('myfrom')
        curl.AddRecipient('myemail') 
        curl.useSSL(CURL_SSLVERSION_DEFAULT)
        curl.setSSLVerifyPeer(False)
        curl.setSSLVerifyHost(False)
        curl.Subject('Test email')
        curl.Body('Test email using libcurl')
        curl.SetOpt(CURLOPT_CONNECTTIMEOUT, 30)
        res = curl.Send()
        IF res = CURLE_OK
            MESSAGE('Email sent', 'SendMail', ICON:Asterisk)
        ELSE
            MESSAGE('Send failed: '& curl.StrError(res), 'SendMail', ICON:Exclamation)
        END

Seems this line is invalid:
curl.useSSL(CURL_SSLVERSION_DEFAULT)
because useSSL method expects one of CURL_USESSL equates, for example CURLUSESSL_ALL; in your code CURL_SSLVERSION_DEFAULT is passed which is zero and therefore no SSL encryption is used. In fact, you call
curl.useSSL(CURLUSESSL_NONE)

wit CURLUSESSL_ALL return access deny, but with nettalk connect correctly, so the credentials is correct

Inspect debugview log.