Sinisterly
[AutoIt]Getting IP, Sending SMTP mail + Other INet functions - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Coding (https://sinister.ly/Forum-Coding--71)
+--- Thread: [AutoIt]Getting IP, Sending SMTP mail + Other INet functions (/Thread-AutoIt-Getting-IP-Sending-SMTP-mail-Other-INet-functions)



[AutoIt]Getting IP, Sending SMTP mail + Other INet functions - 1234hotmaster - 09-28-2011

at the top of your code add
Code:
#include <INet.au3>


INet.au3 Functions:
Code:
_GetIP _INetExplorerCapable _INetGetSource _INetSmtpMail _TCPIpToName


_GetIP gets your Ivp4 IP Adress from a online page so internet connection is required.
Code:
msgbox( 64,"","Your IP is " & _GetIP() )

_INetExplorerCapable converts weird characters and symbols to readable ones so internet explorer can read them and not return a error
Code:
msgbox( 64,"",_INetExplorerCapable("S̶t̶r̶i̶k̶e̶t̶h̶r̶o̶u̶g̶h̶"))

_INetGetSource Gets the source code of a internet page. It can be .html or .txt or etc.
Code:
msgbox( 64,"","The source code of www.google.com is:" & @CRLF & @CRLF & _INetGetSource("www.google.com") )


_INetSmtpMail uses the SMTP service to send e-mails but does not work with gmail or other things so i present you Jos's SMTP UDF that also support attachments and HTML!!
Spoiler:
Code:
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]) If FileExists($S_Files2Attach[$x]) Then ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF) $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 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 $objEmail.Configuration.Fields.Update 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 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) Return EndFunc Func _PathFull($sRelativePath, $sBasePath = @WorkingDir) If Not $sRelativePath Or $sRelativePath = "." Then Return $sBasePath Local $sFullPath = StringReplace($sRelativePath, "/", "\") Local Const $sFullPathConst = $sFullPath Local $sPath Local $bRootOnly = StringLeft($sFullPath, 1) = "\" And StringMid($sFullPath, 2, 1) <> "\" For $i = 1 To 2 $sPath = StringLeft($sFullPath, 2) If $sPath = "\\" Then $sFullPath = StringTrimLeft($sFullPath, 2) Local $nServerLen = StringInStr($sFullPath, "\") -1 $sPath = "\\" & StringLeft($sFullPath, $nServerLen) $sFullPath = StringTrimLeft($sFullPath, $nServerLen) ExitLoop ElseIf StringRight($sPath, 1) = ":" Then $sFullPath = StringTrimLeft($sFullPath, 2) ExitLoop Else $sFullPath = $sBasePath & "\" & $sFullPath EndIf Next. If $i = 3 Then Return "" If StringLeft($sFullPath, 1) <> "\" Then If StringLeft($sFullPathConst, 2) = StringLeft($sBasePath, 2) Then $sFullPath = $sBasePath & "\" & $sFullPath Else $sFullPath = "\" & $sFullPath EndIf EndIf Local $aTemp = StringSplit($sFullPath, "\") Local $aPathParts[$aTemp[0]], $j = 0 For $i = 2 To $aTemp[0] If $aTemp[$i] = ".." Then If $j Then $j -= 1 ElseIf Not ($aTemp[$i] = "" And $i <> $aTemp[0]) And $aTemp[$i] <> "." Then $aPathParts[$j] = $aTemp[$i] $j += 1 EndIf Next $sFullPath = $sPath If Not $bRootOnly Then For $i = 0 To $j - 1 $sFullPath &= "\" & $aPathParts[$i] Next Else $sFullPath &= $sFullPathConst If StringInStr($sFullPath, "..") Then $sFullPath = _PathFull($sFullPath) EndIf While StringInStr($sFullPath, ".\") $sFullPath = StringReplace($sFullPath, ".\", "\") WEnd Return $sFullPath EndFunc

Usage Example:
Code:
_INetSmtpMailCom("smtp.gmail.com","1234hotmaster","soemguy@somesite.com","toguy@yahoo.com","hi testing SMTP","Nothing here to see","","","","Normal","Myuser@gmail.com","Mypass",465,1)

_TCPIpToName Is used for reversing the site's ip back to its address.
Code:
msgbox( 64,"","Your ip's hostname is=" & _TCPIpToName(_GetIP()) )



RE: [AutoIt]Getting IP, Sending SMTP mail + Other INet functions - gunjal_nikhil - 04-01-2012

_GetIP

shows syntex error


RE: [AutoIt]Getting IP, Sending SMTP mail + Other INet functions - Snipa - 04-06-2012

(04-01-2012, 05:57 PM)gunjal_nikhil Wrote: _GetIP

shows syntex error

maybe its _GetIP() ? Smile <== don't forget the parentheses


RE: [AutoIt]Getting IP, Sending SMTP mail + Other INet functions - DiamonD.ZeuS - 12-04-2012

very nice tuts op. thanks for this. this may be usefull for me Wink