Sign in to follow this  
Followers 0

Comcast Internet Usage script

5 posts in this topic

Posted

Hello,

I would post this in the 'Examples' forum but I'm new here & haven't met the restriction requirements for posting there.

Anyway, since Comcast has imposed a 250gb / month limit I wanted an easy way to check my usage. My router contains the info but it isn't accurate. I'm not particularly keen on logging into their site every day, so I made a script that does it instead. I've compiled this as an EXE & run it via Windows Task Scheduler, and it works great.

Thanks to other posters on the board, in particular the _INetSmtpMailCom function!

Script: Comcast Internet Usage Script

What it does: When executed, logs into Comcast.net, reads your current internet usage, emails you that information, then quits IE.

Intended Use: Run via Task Scheduler to receive daily reports

#include <IE.au3>
#include <file.au3>

;##################################
; Variables
;##################################
;Comcast.net user&password
$sUsername = "user@comcast.net"				;comcast username
$sPassword = "password"							;comcast password

;SMTP information
$SmtpServer = "smtp.gmail.com"            			; address for the smtp-server to use - REQUIRED
$FromName = "From Me"               		; name from who the email was sent
$FromAddress = "user@gmail.com"				; address from where the mail should come
$ToAddress = "user@gmail.com"  ; destination address of the email - REQUIRED
$Subject = "Comcast Internet Usage"                 ; subject from the email - can be anything you want it to be
$Username = "user@gmail.com"                 ; username for the account used from where the mail gets sent - REQUIRED
$Password = "password"               				; 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






;##################################
; Comcast Script
;##################################

; Open Comcast usage page redirector - checks for u/p
$oIE = _IECreate("https://login.comcast.net/login?forceAuthn=1&continue=%2fSecure%2fUsers.aspx&s=ccentral-cima&r=comcast.net")

; Get pointers to the login form and username and password fields
$oform = _IEFormGetObjByName($oIE, "login-form")
$ologin = _IEFormElementGetObjByName($oform, "user")
$opassword = _IEFormElementGetObjByName($oform, "passwd")

; Set field values and submit the form
_IEFormElementSetValue($ologin, $sUsername)
_IEFormElementSetValue($opassword, $sPassword)
_IEFormSubmit($oform, 0)

; Comcast uses several redirects, fooling IELoadWait. So check if IE is busy, and if the page is the correct page. IsLoading page is below
$obusy = _IEPropertyGet ( $oIE, "busy" )
While $obusy
    _IELoadWait($oIE, 1000)
	$opage = IsLoading($oIE)
	While $opage
		_IELoadWait($oIE, 1000)
		$opage = IsLoading($oIE)
	WEnd
	$obusy = _IEPropertyGet ( $oIE, "busy" )
WEnd

; Check the usage
$ousage = _IEGetObjById ($oIE, "ctl00_ctl00_ContentArea_PrimaryColumn2Content_ctl00_ctl01_UsageGraphLegend")
$oused = _IEPropertyGet($ousage, "innerhtml")

; Prepare the email message
$Body = "As of today, you have used the following bandwidth:<br /><b>" & $oused & "</b>"  ; First line of message
$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"

; Email the message. Uncomment If Comment to see error messages
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$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

; Quit IE to automate this
_IEQuit ($oIE)


;##################################
; IsLoading Script
;##################################

Func IsLoading($o_IE)
	$o_page = _IEPropertyGet ( $oIE, "locationurl" )
	$loading = True
	If $o_page = "https://customer.comcast.com/Secure/Users.aspx" Then $loading = False
	Return $loading
EndFunc

;##################################
; Mail Script
;##################################
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)
    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

Share this post


Link to post
Share on other sites



Posted

when they tried to do that to me I kept calling for a new IP because my internet was not working lol not really but it works! just act completely computer illiterate.

Share this post


Link to post
Share on other sites

Posted

Here's the script with a table showing how much you can download:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=beta
#AutoIt3Wrapper_outfile=E:\Programs\ComcastUsage.exe
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <IE.au3>
#include <file.au3>
#Include <Date.au3>

;##################################
; Variables
;##################################
;Comcast.net user&password
$sUsername = "user@comcast.net"				;comcast username
$sPassword = "c_password"							;comcast password

;Max Download, in GB, you want in a month
$oMaxDownload = 230

;SMTP information
$SmtpServer = "smtp.gmail.com"            			; address for the smtp-server to use - REQUIRED
$FromName = "User Notifications"               		; name from who the email was sent
$FromAddress = "user@gmail.com"				; address from where the mail should come
$ToAddress = "user@gmail.com"  ; destination address of the email - REQUIRED
$Subject = "Comcast Internet Usage"                 ; subject from the email - can be anything you want it to be
$Username = "user@gmail.com"                 ; username for the account used from where the mail gets sent - REQUIRED
$Password = "g_password"               				; 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

;History File to store in CSV
$HistoryFile = FileOpen("E:\Programs\ComcastUsage\History.csv", 1)


;##################################
; Comcast Script
;##################################

; Open Comcast usage page redirector - checks for u/p
$oIE = _IECreate("https://login.comcast.net/login?forceAuthn=1&continue=%2fSecure%2fUsers.aspx&s=ccentral-cima&r=comcast.net")


; Get pointers to the login form and username and password fields
$oform = _IEFormGetObjByName($oIE, "login-form")
$ologin = _IEFormElementGetObjByName($oform, "user")
$opassword = _IEFormElementGetObjByName($oform, "passwd")

$eform = _IEFormGetObjByName($oIE, "signin")
$elogin = _IEFormElementGetObjByName($eform, "user")
$epassword = _IEFormElementGetObjByName($eform, "passwd")

; Set field values and submit the form
_IEFormElementSetValue($elogin, $sUsername)
_IEFormElementSetValue($epassword, $sPassword)
_IEFormSubmit($eform, 0)

; Set field values and submit the form
_IEFormElementSetValue($ologin, $sUsername)
_IEFormElementSetValue($opassword, $sPassword)
_IEFormSubmit($oform, 0)

; Comcast uses several redirects, fooling IELoadWait. So check if IE is busy, and if the page is the correct page. IsLoading page is below
$obusy = _IEPropertyGet ( $oIE, "busy" )
While $obusy
	_IELoadWait($oIE, 1000)
	$opage = IsLoading($oIE)
	While $opage
		_IELoadWait($oIE, 1000)
		$opage = IsLoading($oIE)
	WEnd
	$obusy = _IEPropertyGet ( $oIE, "busy" )
WEnd


; Check the usage
$oBigContainer = _IEGetObjById ($oIE, "DeviceListContainer")
$oBigUsage = _IEPropertyGet($oBigContainer, "innerhtml")
$oUseContainer = _IEGetObjById  ($oIE, "ctl00_ctl00_ContentArea_PrimaryColumn2Content_ctl00_ctl01_UsageGraphLegend")
$oUsage = _IEPropertyGet($oUseContainer, "innerhtml")

; Calculate Numbers
$oTotalDays = _DateDaysInMonth(@YEAR, @MON)
$oIdealDownload = INT((@MDAY / $oTotalDays) * $oMaxDownload)
$oActualDownload = Int(StringReplace($oUsage, "GB of 250GB", ""))
$oCanDownload = Int($oIdealDownload - $oActualDownload)

; Prepare the email message
$Body = "As of today, you've used <b>" & $oActualDownload & " GB</b> worth of data.<br /><br />The ideal amount  is <b>" & $oIdealDownload & " GB.</b><br />To stay even with your ideal, you can download <b>" & $oCanDownload & " GB</b> worth of data tonight.<br /><br />"
$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"

;Write file to history, in case email doesn't work
FileWrite($HistoryFile,  @MON & "/" & @MDAY & "/" & @YEAR & "," & $oActualDownload & "," & $oIdealDownload & "," & $oCanDownload & @CRLF)
FileClose($HistoryFile)

; Email the message. Uncomment If Commented to see error messages
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$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

; Quit IE to automate this
_IEQuit ($oIE)


;##################################
; IsLoading Script
;##################################

Func IsLoading($o_IE)
	$o_page = _IEPropertyGet ( $oIE, "locationurl" )
	$loading = True
	If $o_page = "https://customer.comcast.com/Secure/Users.aspx" Then $loading = False
	Return $loading
EndFunc

;##################################
; Mail Script
;##################################
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)
    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

Share this post


Link to post
Share on other sites

Posted

And if anyone is interested, here's another generic script. I dumped Comcast a few months ago to an ISP without the bandwidth monitor. So now I use the one built into Tomato Firmware. I have my router setup to save the data to an SMB share, so it isn't lost when I reboot my router:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=beta
#AutoIt3Wrapper_outfile=E:\Programs\ComcastUsage.exe
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <IE.au3>
#include <file.au3>
#Include <Date.au3>
#Include <String.au3>
#include <Array.au3>
#include <Math.au3>

;##################################
; Variables
;##################################
;Comcast.net user&password
$sUsername = "routeruser"				;router username
$sPassword = "routerpassword"							;router password
$sRouter = "10.0.1.1"				;router address

;Max Download, in GB, you want in a month
$oMaxDownload = 220

;SMTP information
$SmtpServer = "smtp.gmail.com"            			; address for the smtp-server to use - REQUIRED
$FromName = "Notifications"               		; name from who the email was sent
$FromAddress = "user@gmail.com"				; address from where the mail should come
$ToAddress = "user+notifications@gmail.com"  ; destination address of the email - REQUIRED
$Subject = "Internet Usage"                 ; subject from the email - can be anything you want it to be
$Username = "user@gmail.com"                 ; username for the account used from where the mail gets sent - REQUIRED
$Password = "g_password"               				; 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

;History File to store in CSV
$HistoryFile = FileOpen("E:\Programs\ComcastUsage\History.csv", 1)


;##################################
; Comcast Script
;##################################

$sLocation = "http://" & $sUsername & ":" & $sPassword & "@" & $sRouter
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE","iexplore.exe","REG_DWORD",0)
$oIE = _IECreate ($sLocation)
RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE","iexplore.exe","REG_DWORD",1)

; Get 30 day bandwidth usage
_IENavigate ($oIE, "http://" & $sRouter & "/bwm-daily.asp")
$b30DayContainer = _IEGetObjById ($oIE, "last-total")
$b30Usage = _IEPropertyGet($b30DayContainer, "innerhtml")
$oTable = _IETableGetCollection ($oIE, 1)
$aTableData = _IETableWriteToArray ($oTable)
$b30day1 = $aTableData[3][30]
$b30day2 = $aTableData[3][29]
$b30day3 = $aTableData[3][28]
$b30date1 = $aTableData[0][30]
$b30date2 = $aTableData[0][29]
$b30date3 = $aTableData[0][28]

; Get monthly bandwidth usage
_IENavigate ($oIE, "http://" & $sRouter & "/bwm-monthly.asp")
$oTable = _IETableGetCollection ($oIE, 1)
$aTableData = _IETableWriteToArray ($oTable)
$bMonthUsage = $aTableData[3][1]


; Quit IE
_IEQuit ($oIE)

; Calculate Numbers
$oTotalDays = _DateDaysInMonth(@YEAR, @MON)
$oIdealDownload = INT((@MDAY / $oTotalDays) * $oMaxDownload)
$oActualDownloadMonth = Int(StringReplace($bMonthUsage, "GB", ""))
$oActualDownload30 = Int(StringReplace($b30Usage, "GB", ""))
$oCanDownloadMonth = Int($oIdealDownload - $oActualDownloadMonth)
$oCanDownload30 = Int($oMaxDownload - $oActualDownload30)
$oSafeNumber = _Min($oCanDownload30, $oCanDownloadMonth)

;Write file to history, in case email doesn't work
FileWrite($HistoryFile,  @MON & "/" & @MDAY & "/" & @YEAR & "," & $oActualDownloadMonth & "," & $oIdealDownload & "," & $oSafeNumber & @CRLF)
FileClose($HistoryFile)

; Prepare the email message
$Body = "<html><head><style type='text/css'>body{font: 14px trebuchet ms,sans-serif;}table, th {	border-width: 1px;	border-style: outset;	border-color: gray;	border-collapse: collapse;}td {border-width: 1px;text-align: right;        padding: 5px;	border-style: outset;	border-color: gray;}</style></style></head><body><h3>Internet Usage</h3><p>To be safe, you can download <strong>" & $oSafeNumber & " GB</strong> tonight.</p><p>Here's the actual internet usage:</p><table><tr><th>&nbsp;</th><th>30 Days</th><th>Month</th></tr><tr><td style='text-align:left;'>Actual Used:</td><td>" & $oActualDownload30 & " GB</td><td>" & $oActualDownloadMonth & " GB</td></tr><tr><td style='text-align:left;'>Ideal Used:</td><td>" & $oMaxDownload & " GB</td><td>" & $oIdealDownload & " GB</td></tr></table><br /><br /><h3>Usage 30 days ago:</h3><table><tr><th>" & $b30date1 & "</th><th>" & $b30date2 & "</th><th>" & $b30date3 & "</th></tr><tr><td>" & $b30day1 & "</td><td>" & $b30day2 & "</td><td>" & $b30day3 & "</td></tr></table></body></html>"
$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"



; Email the message. Uncomment If Commented to see error messages
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$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





;##################################
; Mail Script
;##################################
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)
    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

Share this post


Link to post
Share on other sites

Posted

the script does not seem to work anymore. Does anyone know how to fix it?

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  
Followers 0




  • Recently Browsing   0 members

    No registered users viewing this page.