Jump to content

Recommended Posts

Posted

I was just reminded of this. Windows 10 (and later) started shipping with curl.exe natively in 2017, so I wonder if they ship the DLL too? I don't have a Windows machine handy to check, so please let me know if you do :)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

  • 2 months later...
Posted

Much Thanks, Beege

I had used ward's version for several years. I'm so excited to know there was new version of Curl UDF being released. I'll try it out later and come back to let you know what  I had done .

Asparagus 
 

Posted

@Beege could you be so nice and create example how to use with POP3, POP3S, SMTP, SMTPS, IMAP, IMAPS ?
It would became an awesome EMAIL UDF.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 6/14/2022 at 7:37 AM, mLipok said:

@Beege could you be so nice and create example how to use with POP3, POP3S, SMTP, SMTPS, IMAP, IMAPS ?
It would became an awesome EMAIL UDF.

Expand  

@mLipok here is a small example demonstrating retrieving an email using either pop3,pop3s,imap,imaps. Ill work on smtp,smtps next :)

; #FUNCTION# ====================================================================================================================
; Name ..........: Example_Email_Fetch
; Description ...: Fetch message 1 from inbox
; Parameters ....: $sServer             - server address. ex: imap.comcast.net
;                  $sUser               - username/email address
;                  $sPass               - password
;                  $sProt               - protocol. imap,imaps,pop3,pop3s
; ===============================================================================================================================
Func Example_Email_Fetch($sServer, $sUser, $sPass, $sProt = 'imaps')

    Local $Curl = Curl_Easy_Init()
    If Not $Curl Then Return

    Local $emsg = $Curl

    ;Set username and password
    Curl_Easy_Setopt($Curl, $CURLOPT_USERNAME, $sUser) ;
    Curl_Easy_Setopt($Curl, $CURLOPT_PASSWORD, $sPass) ;

    ;This will fetch message 1 (oldest message) from the user's inbox
    Switch $sProt
        Case 'imaps'
            Curl_Easy_Setopt($Curl, $CURLOPT_URL, "imaps://" & $sServer & "/INBOX/;UID=1") ;
        Case 'imap'
            Curl_Easy_Setopt($Curl, $CURLOPT_URL, "imap://" & $sServer & "/INBOX/;UID=1") ;
            Curl_Easy_Setopt($Curl, $CURLOPT_USE_SSL, $CURLUSESSL_ALL) ;
        Case 'pop3s'
            Curl_Easy_Setopt($Curl, $CURLOPT_URL, "pop3s://" & $sServer & "/1") ;
        Case 'pop3'
            Curl_Easy_Setopt($Curl, $CURLOPT_URL, "pop3://" & $sServer & "/1") ;
            Curl_Easy_Setopt($Curl, $CURLOPT_USE_SSL, $CURLUSESSL_ALL) ;
        Case Else
            Return ConsoleWrite('Invalid Protocol' & @CRLF)
    EndSwitch

    ;Set ca bundle for peer verification
    Curl_Easy_Setopt($Curl, $CURLOPT_CAINFO, @ScriptDir & '\curl-ca-bundle.crt') ;

    ;Set Callback to recive msg
    Curl_Easy_Setopt($Curl, $CURLOPT_WRITEFUNCTION, Curl_DataWriteCallback())
    Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $emsg)

    ;show extra connection info
    Curl_Easy_Setopt($Curl, $CURLOPT_VERBOSE, 1) ;

    ;Perform the fetch
    $Code = Curl_Easy_Perform($Curl) ;
    If $Code = $CURLE_OK Then
        ConsoleWrite('email msg:' & @CRLF & BinaryToString(Curl_Data_Get($emsg)))
    Else
        ConsoleWrite(Curl_Easy_StrError($Code) & @LF)
    EndIf

    ;cleanup
    Curl_Easy_Cleanup($Curl)
    Curl_Data_Cleanup($emsg)

    Return $Code ;
EndFunc   ;==>Example_Email_Fetch

 

Posted

Does it download a single email?
How to get the list to be downloaded first and then looped to download email by email?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 6/19/2022 at 12:29 AM, Beege said:

Ill work on smtp,smtps next

Expand  

When you start to work on SMTP please remember about feature which will let users to save sent email via IMAP to SENT message box.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 6/19/2022 at 10:18 AM, mLipok said:

Does it download a single email?

Expand  

oh I see you are using 

;UID=1

this mean that yours example get single email.

  So:

  On 6/19/2022 at 10:18 AM, mLipok said:

How to get the list to be downloaded first and then looped to download email by email?

Expand  

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 6/19/2022 at 10:29 AM, mLipok said:

oh I see you are using 

;UID=1

this mean that yours example get single email.

Expand  

In *nix UID usually refers to User ID so it's probably referring to the mailbox belonging to the user with ID = 1

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted (edited)

https://stackoverflow.com/a/37163120/5314940

UID is the unique identification number of a email in a IMAP folder. Each mail in a folder is assigned a uid, it is you can say a index maintained by the mail folder. Whereas message-id is a header part of a email.

To understand in a simple term, UID is a unique number which cannot be duplicated within a folder

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 6/19/2022 at 10:25 AM, mLipok said:

When you start to work on SMTP please remember about feature which will let users to save sent email via IMAP to SENT message box.

Expand  

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

 

Posted (edited)

As so far I was not able to take a look at your UDF internal code.

Hope I be able to do this in june.

But this is on my list.

Then I hope that I will be able to be more helpfull with append the sent email to sent mailbox.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 6/19/2022 at 3:15 PM, mLipok said:
Expand  

Nice! I just got a custom request working asking for total count of messages in the inbox which falls inline with what we need to do for the EXAMINE command they talk about. I found this link too with a bunch other custom requests that can be used. All the -X ones. https://gist.github.com/akpoff/53ac391037ae2f2d376214eac4a23634

Func Example_Email_Count($sServer, $sUser, $sPass)

    Local $Curl = Curl_Easy_Init()
    If Not $Curl Then Return

    Local $emsg = $Curl

    ;set options
    Curl_Easy_Setopt($Curl, $CURLOPT_USERNAME, $sUser) ;
    Curl_Easy_Setopt($Curl, $CURLOPT_PASSWORD, $sPass) ;
    Curl_Easy_Setopt($Curl, $CURLOPT_CAINFO, @ScriptDir & '\curl-ca-bundle.crt') ;
    Curl_Easy_Setopt($Curl, $CURLOPT_WRITEFUNCTION, Curl_DataWriteCallback())
    Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $emsg)
    ;Curl_Easy_Setopt($Curl, $CURLOPT_VERBOSE, 1) ;
    
    ;Request count of messeges in inbox
    Curl_Easy_Setopt($Curl, $CURLOPT_CUSTOMREQUEST, "STATUS INBOX (MESSAGES)") ;
    Curl_Easy_Setopt($Curl, $CURLOPT_URL, "imaps://" & $sServer) ;

    $Code = Curl_Easy_Perform($Curl)     ;
    If $Code = $CURLE_OK Then
        ConsoleWrite('email count ' & @CRLF & BinaryToString(Curl_Data_Get($emsg)) & @CRLF & '----****------' & @CRLF)
    Else
        ConsoleWrite(Curl_Easy_StrError($Code) & @LF)
    EndIf
    
    Curl_Data_Cleanup($emsg)
    Curl_Easy_Cleanup($Curl)

EndFunc   ;==>Example_Email_Count

Output:

email count:
* STATUS INBOX (MESSAGES 61)

 

Posted
  On 6/19/2022 at 3:15 PM, mLipok said:
Expand  

After sending email with SMTP or IMAP you should be able to get the "EMAIL" content and append them to "INBOX.Sent" or to "Sent" mailbox.

This is how I do this with Chilkat AX component.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Here's a small example showing how to loop through the emails. This will print the subject line of the first 100 emails from the inbox.

 

Func Example_Email_Subjects($sServer, $sUser, $sPass)

    Local $Curl = Curl_Easy_Init()
    If Not $Curl Then Return

    Local $emsg = $Curl

    Curl_Easy_Setopt($Curl, $CURLOPT_USERNAME, $sUser) ;
    Curl_Easy_Setopt($Curl, $CURLOPT_PASSWORD, $sPass) ;
    Curl_Easy_Setopt($Curl, $CURLOPT_CAINFO, @ScriptDir & '\curl-ca-bundle.crt') ;
    Curl_Easy_Setopt($Curl, $CURLOPT_WRITEFUNCTION, Curl_DataWriteCallback())
    Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $emsg)
    ;Curl_Easy_Setopt($Curl, $CURLOPT_VERBOSE, 1) ;

    For $i = 1 To 100
        ; get full email
        ;Curl_Easy_Setopt($Curl, $CURLOPT_URL, "imaps://" & $sServer & "/INBOX/;UID=" & $i)
        
        ; get subject only
        ;Curl_Easy_Setopt($Curl, $CURLOPT_URL, "imaps://" & $sServer & "/INBOX/;UID=" & $i & ";SECTION=HEADER.FIELDS%20(SUBJECT)") 
        
        ; get date,from,to,subject only
        Curl_Easy_Setopt($Curl, $CURLOPT_URL, "imaps://" & $sServer & "/INBOX/;UID=" & $i & ";SECTION=HEADER.FIELDS%20(DATE%20FROM%20TO%20SUBJECT)")

        $Code = Curl_Easy_Perform($Curl) ;
        If $Code = $CURLE_OK Then
            ConsoleWrite($i & ': ' & BinaryToString(Curl_Data_Get($emsg)) & @CRLF)
            Curl_Data_Cleanup($emsg); clear data
        Else
            ConsoleWrite(Curl_Easy_StrError($Code) & @LF)
            ExitLoop
        EndIf

    Next

    Curl_Easy_Cleanup($Curl)
    
EndFunc   ;==>Example_Email_Subjects

 

Edited by Beege

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...