Jump to content
Sign in to follow this  
therestorestore

Email Check / Parse / Forward

Recommended Posts

therestorestore

Hello All-

I've been dabbling with some AutoIT scripts and so on, I think it's a very powerful and impressive tool.

I've got a Verizon phone here in the US, and I have data and texting. The problem is, the email program provided by verizon (this isn't a full blown smart phone) is really really lousy.

Right now I have Gmail forwarding all incoming emails to my phone automatically as a text. I know instantly when I get an email. The problem is, the bulk of the text message that I see is useless. Plus, there are several emails I simply don't need to see on my phone.

What I want to do is write a script that will manage my emails for me. I want to check the gmail, parse the key information, forward the wanted emails (cleaned) as an SMS, ditch the non-wanted emails, rinse and repeat. I have some machines I can run this on that can run 24/7 etc. I'm hesitant to try kludging something on thunderbird or outlook, etc. I think what I really need is a purpose built program. I've googled for something already made and I've searched on here.

I've been playing around with bits and pieces of code that have been posted on here, there are scripts posted that check Gmail, scripts that send Gmail, etc, but I haven't really had any luck putting something together that "works" as a 24/7 tool to monitor emails.

I'm not necessarily adept enough to create something 100% from scratch, but I think the key components for this script have already been established anyway.

Any suggestions for reference scripts that will get me going in the right direction?

Has this been done before?

I think that figuring out something like this would be really useful for people other than just me.

TIA...

Share this post


Link to post
Share on other sites
PsaltyDS

Have you downloaded AutoIt and the SciTE4AutoIt3 editor? Run the tutorials? What did you try? How far did you get? What stopped you?

Having already found example code, what was the AutoIt question here?

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
anixon

Hello All-

I've been dabbling with some AutoIT scripts and so on, I think it's a very powerful and impressive tool.

I've got a Verizon phone here in the US, and I have data and texting. The problem is, the email program provided by verizon (this isn't a full blown smart phone) is really really lousy.

Right now I have Gmail forwarding all incoming emails to my phone automatically as a text. I know instantly when I get an email. The problem is, the bulk of the text message that I see is useless. Plus, there are several emails I simply don't need to see on my phone.

What I want to do is write a script that will manage my emails for me. I want to check the gmail, parse the key information, forward the wanted emails (cleaned) as an SMS, ditch the non-wanted emails, rinse and repeat. I have some machines I can run this on that can run 24/7 etc. I'm hesitant to try kludging something on thunderbird or outlook, etc. I think what I really need is a purpose built program. I've googled for something already made and I've searched on here.

I've been playing around with bits and pieces of code that have been posted on here, there are scripts posted that check Gmail, scripts that send Gmail, etc, but I haven't really had any luck putting something together that "works" as a 24/7 tool to monitor emails.

I'm not necessarily adept enough to create something 100% from scratch, but I think the key components for this script have already been established anyway.

Have a look at the 'Wooltown' Outlook API in this forum which might be a starting point.. Ant

Any suggestions for reference scripts that will get me going in the right direction?

Has this been done before?

I think that figuring out something like this would be really useful for people other than just me.

TIA...

Share this post


Link to post
Share on other sites
therestorestore

Ok...

Finally getting back to this post. Sorry.

Yep, I've got the autoit installed, I've made some programs and so on.

A commercial product that sortof does what I'm after is called "versaforward" but it is pricey, overkill, and doesn't quite support gmail.

After researching for gmail sample code, I found these code samples. Kudos to the kind folks who posted them.

This is a SSL POP script:

#include <Array.au3>
#include "POP_ssl_V3.2.au3"


Opt("OnExitFunc", "endscript")
Opt("SendKeyDelay", 0)
Opt("TrayIconDebug", 1)

;kill previous run
While ProcessExists("openssl.exe")
    ProcessClose("cmd.exe")
    ProcessClose("openssl.exe")
WEnd

;###FILL IN THIS INFO###
$User = InputBox("Gmail", "Enter Username", "")
$Pass = InputBox("Gmail", "Enter Password", "", "*")

;set server info
$SSL_Exe_loc = "C:\OpenSSL\bin\openssl.exe"
$POP_Server = "pop.gmail.com"
$POP_Port = "995"
$error = ""

$msg = _POP_Connect($POP_Server, $POP_Port, $SSL_Exe_loc, True)
;MsgBox(0, $msg & " - " & @error, $_POP_Log)
$error &= $msg & " - " & @error & @CRLF

If $msg == False Then EndReport($error)
$msg = _POP_Login($User, $Pass)
;MsgBox(0, $msg & " - " & @error, $_POP_Log)
$error &= $msg & " - " & @error & @CRLF

If $msg == False Then EndReport($error)
$msg = _POP_GetStats()
MsgBox(0, "", $msg)
$error &= $msg & " - " & @error & @CRLF

If $msg == False Then EndReport($error)
$msg = _POP_GetList()
_ArrayDisplay($msg)
$error &= $msg & " - " & @error & @CRLF

$msg = _POP_GetMessage(1)
_ArrayDisplay($msg)
$error &= $msg & " - " & @error & @CRLF

$msg = _POP_Disconnect()
$error &= $msg & " - " & @error & @CRLF


EndReport($error)
Func EndReport($error)
    MsgBox(0, "", $error)
    Exit
EndFunc   ;==>EndReport

This is a SSL SMTP script:

#include <Array.au3>
#include "_Base64.au3"
#include "SMTP-ssl_V3.0.au3"
$default = "Username"


Opt("OnExitFunc", "endscript")
Opt("SendKeyDelay", 0)
Opt("TrayIconDebug", 1)

;kill previous run
While ProcessExists("openssl.exe")
    ProcessClose("cmd.exe")
    ProcessClose("openssl.exe")
WEnd

;###FILL IN THIS INFO###
;set user/pass
$user = _Base64Encode(InputBox("Username", "Username", $default))
$pass = _Base64Encode(InputBox("Password", "Password", "", "*"))

;set message info
$s_ToAddress = InputBox("To", "To Address", $default & "@gmail.com")
$s_FromName = InputBox("From Name", "From Name", $default)
$s_FromAddress = InputBox("From", "From Address", $default & "@gmail.com")
$s_Subject = "UDF Test"
Dim $as_Body[2]
$as_Body[0] = "Testing the new email udf"
$as_Body[1] = "Second Line"

;build body of email
$BodyString = ""
For $i = 0 To UBound($as_Body) - 1 Step +1
    $BodyString = $BodyString & $as_Body[$i] & @CRLF
Next

;set server info
$SSL_Exe_loc = "C:\OpenSSL\bin\openssl.exe"
$SMTP_Server = "smtp.gmail.com"
$SMTP_Port = "465"
$error = ""

$msg = _SMTP_Connect($SMTP_Server, $SMTP_Port, $SSL_Exe_loc, True)
;MsgBox(0, $msg & " - " & @error, $_SMTP_Log)
$error &= $msg & " - " & @error & @CRLF

$msg = _SMTP_Login($user, $pass)
;MsgBox(0, $msg & " - " & @error, $_SMTP_Log)
$error &= $msg & " - " & @error & @CRLF

$msg = _SMTP_SendEmail($s_ToAddress, $s_FromAddress, $s_FromName, $s_Subject, $BodyString)
;MsgBox(0, $msg & " - " & @error, $_SMTP_Log)
$error &= $msg & " - " & @error & @CRLF

$msg = _SMTP_Disconnect()
;MsgBox(0, $msg & " - " & @error, $_SMTP_Log)
$error &= $msg & " - " & @error & @CRLF
MsgBox(0, "", $error)

So, basically, what I'd want to do is combine the two scripts, have it run all the time, and forward new gmails to my cell phone and they show up as quick and tidy sms. I'd put in a white/black list, do some parsing and processing, etc. PERFECT!

The problems I've had seems to be something to do with the way it calls the SSL. I have got it to sit and check, and then forward, once, then stop. And, I've got it to "run" all the time, but do nothing.

If you want to see my hack job of putting these scripts together, here it is. I am not a professional programmer! This is not finished, but it is the one that WILL check and send the message, parsed, one time.

#include <Array.au3>
#include "POP_ssl_V3.2.au3"
#Include<file.au3>


Opt("OnExitFunc", "endscript")
Opt("SendKeyDelay", 0)
Opt("TrayIconDebug", 1)



;kill previous run
While ProcessExists("openssl.exe")
    ProcessClose("cmd.exe")
    ProcessClose("openssl.exe")
WEnd

;###FILL IN THIS INFO###
$User = (removed)
$Pass = (removed)
$subj=""
$from=""
$to=""

;outgoing vars
$SmtpServer = (removed)              ; address for the smtp-server to use - REQUIRED
$FromName = (removed)                      ; name from who the email was sent
$FromAddress = (removed) ; address from where the mail should come
$ToAddress = (removed)   ; destination address of the email - REQUIRED
$Subject = $subj                   ; subject from the email - can be anything you want it to be
$Body = ""                              ; the messagebody from the mail - can be left blank but then you get a blank mail
$AttachFiles = ""                       ; the file you want to attach- leave blank if not needed
$CcAddress = ""       ; address for cc - leave blank if not needed
$BccAddress = ""     ; address for bcc - leave blank if not needed
$Importance = "Normal"                  ; Send message priority: "High", "Normal", "Low"
$Username = (removed)                    ; username for the account used from where the mail gets sent - REQUIRED
$Password = (removed)                  ; password for the account used from where the mail gets sent - REQUIRED
$IPPort = 25                            ; port used for sending the mail
$ssl = 0                                ; enables/disables secure socket layer sending - put to 1 if using httpS
;$IPPort=465                          ; GMAIL port used for sending the mail
;$ssl=1                               ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS

Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

;set server info
$SSL_Exe_loc = "C:\OpenSSL\bin\openssl.exe"
$POP_Server = "pop.gmail.com"
$POP_Port = "995"
$error = ""
while 1
    
$msg = _POP_Connect($POP_Server, $POP_Port, $SSL_Exe_loc, True)
msgbox(4096,"note","checking mail", 5)

MsgBox(0, $msg & " - " & @error, $_POP_Log)
$error &= $msg & " - " & @error & @CRLF

If $msg == False Then $msg = _POP_Login($User, $Pass)
MsgBox(0, $msg & " - " & @error, $_POP_Log)
$error &= $msg & " - " & @error & @CRLF

If $msg == False Then $msg = _POP_GetStats()
MsgBox(0, "", $msg)
$error &= $msg & " - " & @error & @CRLF

If $msg == False Then $msg = _POP_GetList()
_ArrayDisplay($msg)
$error &= $msg & " - " & @error & @CRLF

$msg = _POP_GetMessage(1)
_ArrayDisplay($msg)
$split=stringsplit($msg, @CR)
_ArrayDisplay($split)
if $split[0]>0 Then
    msgbox(4096,"note","processing mail", 5)
    for $element = 0 to $split[0]
        ;MsgBox(0, "individual line", $split[$element])
        if stringinstr($split[$element], "Subject:") Then
             $subj= $split[$element]
             $Subject= $subj
            EndIf
        if stringinstr($split[$element], "To:") Then
             $to= $split[$element]
            EndIf
        if stringinstr($split[$element], "From:") Then
             $from= $split[$element]
             $FromAddress= $from
            EndIf
        ;$element = $element+1
    next
    $parsedmsg = $from & @CR & $to & @CR & $subj
    MsgBox(0, "", $parsedmsg)
;outgoing email
    $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
    If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & "  Description:" & $rc)
    EndIf

EndIf
;$error &= $msg & " - " & @error & @CRLF

$msg = _POP_Disconnect()
;$error &= $msg & " - " & @error & @CRLF
WEnd
;EndReport($error)
Func EndReport($error)
    MsgBox(0, "", $error)
    Exit
EndFunc   ;==>EndReport

; The UDF
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
    msgbox(4096,"note","sending mail", 5)
    Local $objEmail = ObjCreate("CDO.Message")
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
    $objEmail.To = $s_ToAddress
    Local $i_Error = 0
    Local $i_Error_desciption = ""
    If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
    If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
    $objEmail.Subject = $s_Subject
    If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
        $objEmail.HTMLBody = $as_Body
    Else
        $objEmail.Textbody = $as_Body & @CRLF
    EndIf
    If $s_AttachFiles <> "" Then
        Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
        For $x = 1 To $S_Files2Attach[0]
            $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
            ConsoleWrite('@@ Debug(62) : $S_Files2Attach = ' & $S_Files2Attach & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
            If FileExists($S_Files2Attach[$x]) Then
                $objEmail.AddAttachment ($S_Files2Attach[$x])
            Else
                ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
                SetError(1)
                Return 0
            EndIf
        Next
    EndIf
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
    If Number($IPPort) = 0 then $IPPort = 25
    $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
    ;Authenticated SMTP
    If $s_Username <> "" Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
    EndIf
    If $ssl Then
        $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    EndIf
    ;Update settings
    $objEmail.Configuration.Fields.Update
    ; Set Email Importance
    Switch $s_Importance
        Case "High"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
        Case "Normal"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
        Case "Low"
            $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
    EndSwitch
    $objEmail.Fields.Update
    ; Sent the Message
    $objEmail.Send
    If @error Then
        SetError(2)
        Return $oMyRet[1]
    EndIf
    $objEmail=""
EndFunc   ;==>_INetSmtpMailCom
;
;
; Com Error Handler
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    $oMyRet[0] = $HexNumber
    $oMyRet[1] = StringStripWS($oMyError.description, 3)
    ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
    SetError(1); something to check for when this function returns
    Return
EndFunc   ;==>MyErrFunc

So, is there anything salvageable that can be made to work properly?

Any ideas?

Edited by therestorestore

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.