I was able to get a minimal example going for sending an email via smtp/smtps but it does not save to the sent box. Is that how this is actually implemented? Some kind of combination of using both smtp and imap/pop3? I never thought about what actually makes that happen with the sent messages. I'm mainly working of the examples here https://curl.se/libcurl/c/example.html if anyone else wants to tinker with whatever options exist for the protocols.
; #FUNCTION# ====================================================================================================================
; Name ..........: Example_Email_Send
; Description ...: Send a Email
; Parameters ....: $sServer - server address. ex: smtp.comcast.net
; $sUser - username/email address
; $sPass - password
; $sTo - recepient address
; $sFrom - sender address
; $sSubject - email subject
; $sBody - email body
; $sProt - protocol. smtp/smtps
; ===============================================================================================================================
Func Example_Email_Send($sServer, $sUser, $sPass, $sTo, $sFrom, $sSubject, $sBody, $sProt = 'smtp')
;Build email
Local $sHeaders = "To: <" & $sTo & ">" & @CRLF
$sHeaders &= "From: <" & $sFrom & ">" & @CRLF
;~ $sHeaders &= "CC: <" & $sCC & ">" & @CRLF
;~ $sHeaders &= "BCC: <" & $sBCC & ">" & @CRLF
$sHeaders &= "Subject: " & $sSubject & @CRLF
Local $sEmail = $sHeaders & @CRLF & $sBody
Local $Curl = Curl_Easy_Init()
If Not $Curl Then Return
;Set username and password
Curl_Easy_Setopt($Curl, $CURLOPT_USERNAME, $sUser) ;
Curl_Easy_Setopt($Curl, $CURLOPT_PASSWORD, $sPass) ;
;set server address and protocol
If $sProt = "smtp" Then
Curl_Easy_Setopt($Curl, $CURLOPT_URL, "smtp://" & $sServer & ":587") ;
Curl_Easy_Setopt($Curl, $CURLOPT_USE_SSL, $CURLUSESSL_ALL) ;
ElseIf $sProt = "smtps" Then
Curl_Easy_Setopt($Curl, $CURLOPT_URL, "smtps://" & $sServer) ;
Else
Return ConsoleWrite("invalid protocol" & @CRLF)
EndIf
;Set ca bundle for peer verification
Curl_Easy_Setopt($Curl, $CURLOPT_CAINFO, @ScriptDir & '\curl-ca-bundle.crt') ;
;build and set recipient list
Local $recipients = Curl_Slist_Append(0, $sTo) ;
;$recipients = Curl_Slist_Append($recipients, $sCC);
;$recipients = Curl_Slist_Append($recipients, $sBCC);
Curl_Easy_Setopt($Curl, $CURLOPT_MAIL_RCPT, $recipients) ;
;set from address
Curl_Easy_Setopt($Curl, $CURLOPT_MAIL_FROM, $sFrom) ;
;Set email data and callback
Curl_Data_Put($Curl, $sEmail)
Curl_Easy_Setopt($Curl, $CURLOPT_UPLOAD, 1)
Curl_Easy_Setopt($Curl, $CURLOPT_READFUNCTION, Curl_DataReadCallback())
Curl_Easy_Setopt($Curl, $CURLOPT_READDATA, $Curl)
;show extra connection info
Curl_Easy_Setopt($Curl, $CURLOPT_VERBOSE, 1) ;
;Send email
Local $Code = Curl_Easy_Perform($Curl)
If $Code = $CURLE_OK Then
ConsoleWrite('Email Sent!' & @CRLF)
Else
ConsoleWrite(Curl_Easy_StrError($Code) & @LF)
EndIf
;cleanup
Curl_Slist_Free_All($recipients) ;
Curl_Easy_Cleanup($Curl) ;
EndFunc ;==>Example_Email_Send