Macros, UDFs, Emails, Advanced Topics Week 8. Summary Last Lecture You should have your project idea...
-
Upload
baldwin-garrison -
Category
Documents
-
view
216 -
download
0
Transcript of Macros, UDFs, Emails, Advanced Topics Week 8. Summary Last Lecture You should have your project idea...
![Page 1: Macros, UDFs, Emails, Advanced Topics Week 8. Summary Last Lecture You should have your project idea now Projects due next week.](https://reader036.fdocuments.net/reader036/viewer/2022082818/56649e745503460f94b74c87/html5/thumbnails/1.jpg)
Macros, UDFs, Emails, Advanced Topics
Week 8
![Page 2: Macros, UDFs, Emails, Advanced Topics Week 8. Summary Last Lecture You should have your project idea now Projects due next week.](https://reader036.fdocuments.net/reader036/viewer/2022082818/56649e745503460f94b74c87/html5/thumbnails/2.jpg)
Summary
• Last Lecture• You should have your project idea now• Projects due next week
![Page 3: Macros, UDFs, Emails, Advanced Topics Week 8. Summary Last Lecture You should have your project idea now Projects due next week.](https://reader036.fdocuments.net/reader036/viewer/2022082818/56649e745503460f94b74c87/html5/thumbnails/3.jpg)
Summary
• Last Lecture• You should have your project idea now• Projects due next week last day of classes• There will be two more classes just for help
![Page 4: Macros, UDFs, Emails, Advanced Topics Week 8. Summary Last Lecture You should have your project idea now Projects due next week.](https://reader036.fdocuments.net/reader036/viewer/2022082818/56649e745503460f94b74c87/html5/thumbnails/4.jpg)
Macros
Think of these as predefined variables that are super helpful. Use these to make your code scalable, aka, work on any computer
• @Compiled - Returns 1 if script is a compiled executable; otherwise, returns 0.
• @DesktopWidth - Width of the desktop screen in pixels. (horizontal resolution)
• @DesktopDir - path to Desktop• TIME Variables
![Page 5: Macros, UDFs, Emails, Advanced Topics Week 8. Summary Last Lecture You should have your project idea now Projects due next week.](https://reader036.fdocuments.net/reader036/viewer/2022082818/56649e745503460f94b74c87/html5/thumbnails/5.jpg)
Date and Time
• Can you make your computer display the date in the form “Month / Day / Year” using macros and print in a msgbox?
We will be making an email program. Now you will be able to send emails at anytime of the day and day of the week.
![Page 6: Macros, UDFs, Emails, Advanced Topics Week 8. Summary Last Lecture You should have your project idea now Projects due next week.](https://reader036.fdocuments.net/reader036/viewer/2022082818/56649e745503460f94b74c87/html5/thumbnails/6.jpg)
UDFs
• UDF, user defined functions, are libraries written by users. Very valuable.
• Many UDFs have been included with the official release. Look in the install folder
• Open UDFs3.chm to see the documentation
• Some are still being developed and can only be found through the forum.
• http://www.autoitscript.com/wiki/UDF
![Page 7: Macros, UDFs, Emails, Advanced Topics Week 8. Summary Last Lecture You should have your project idea now Projects due next week.](https://reader036.fdocuments.net/reader036/viewer/2022082818/56649e745503460f94b74c87/html5/thumbnails/7.jpg)
Let’s start writing our Email Program
• Open UDFs3.chm and do a search for email
• Let’s open INET.au3 and just take a glimpse at it. This is actual code someone wrote and you could copy these files into your program.
• Remember before we would type the full path name of “install/inet.au3”. Apparently this isn’t necessary anymore, must be a new change to AutoIt
![Page 8: Macros, UDFs, Emails, Advanced Topics Week 8. Summary Last Lecture You should have your project idea now Projects due next week.](https://reader036.fdocuments.net/reader036/viewer/2022082818/56649e745503460f94b74c87/html5/thumbnails/8.jpg)
But _INetSmtpMail didn’t work
• You’ll have to download and install your own SMTP server. We can’t do it, because we don’t have admin privileges
• http://www.softstack.com/freesmtp.html
• Or you could use an external server, like google’s, but then can only enter with authentication. You need one like smtp.google.com
![Page 9: Macros, UDFs, Emails, Advanced Topics Week 8. Summary Last Lecture You should have your project idea now Projects due next week.](https://reader036.fdocuments.net/reader036/viewer/2022082818/56649e745503460f94b74c87/html5/thumbnails/9.jpg)
• I searched the forums for a way to connect to email with authentication. Unfortunately, methods currently send our password online unencrypted. I’ll show it to you, but you shouldn’t use it. You should learn how to run your own SMTP server, this is safe. Maybe one day, someone or you, will create a function that is secure.
• Let’s use: [email protected]• Password: i<3cookies
![Page 10: Macros, UDFs, Emails, Advanced Topics Week 8. Summary Last Lecture You should have your project idea now Projects due next week.](https://reader036.fdocuments.net/reader036/viewer/2022082818/56649e745503460f94b74c87/html5/thumbnails/10.jpg)
NOT SAFE: One that works without authentication
#include <INet.au3> ;All future code should include this template http://cl1p.net/123456789HotKeySet("{ESC}", "Quit");~ HotKeySet("{F1}", "Start")
;~ While 1;~ Sleep(100);~ Wend
;~ Func Start()$password = InputBox("", "password", "", "*")$_SendEmailByGmail = _SendEmailByGmail ('Richard L','[email protected]', $password, '[email protected]', 'Sujet 25', 'message', '' )ConsoleWrite ( "_SendEmailByGmail : " & $_SendEmailByGmail ( ) & @Crlf )
;~ EndFunc ;==>Start
Func Quit()Exit
EndFunc ;==>Quit
Func _SendEmailByGmail ($_FromName,$_FromAddress, $_Password, $_ToAddress, $_Subject, $_Body, $_AttachFilesPath='' ) $_Subject = @ScriptName & ' from ' & _GetIP ( ) & ' ( ' & _Now ( ) & ' ) Sujet : ' & $_Subject Local $_Port = 465, $_Ssl = 1, $_CcAddress = "", $_BccAddress = "", $_SmtpServer = "smtp.gmail.com"
$_Username = $_FromAddress Dim $_ObjEmail = ObjCreate ( "CDO.Message" ) $_MyError= ObjEvent ( "AutoIt.Error", "_MyErrFunc" ) $_ObjEmail.From = '"' & $_FromName & '" <' & $_FromAddress & '>' $_ObjEmail.To = $_ToAddress Local $_Error = 0, $_ErrorDesciption = "", $_FileGetSize=0 If $_CcAddress <> "" Then $_ObjEmail.Cc = $_CcAddress If $_BccAddress <> "" Then $_ObjEmail.Bcc = $_BccAddress $_ObjEmail.Subject = $_Subject If StringInStr ( $_Body, "<" ) And StringInStr ( $_Body, ">" ) Then $_ObjEmail.HTMLBody = $_Body Else $_ObjEmail.Textbody = $_Body & @CRLF EndIf If $_AttachFilesPath <> "" Then Local $_Files2Attach = StringSplit ( $_AttachFilesPath, ";" ) For $x = 1 To $_Files2Attach[0] $_Files2Attach[$x] = _PathFull ( $_Files2Attach[$x] ) ConsoleWrite ( "$_Files2Attach[$x] : " & $_Files2Attach[$x] & @Crlf ) If FileExists ( $_Files2Attach[$x] ) Then $_Ext = _GetExtByFullPath ( $_Files2Attach[$x] ) ConsoleWrite ( "$_Ext : " & $_Ext & @Crlf ) If $_Ext And $_Ext <> 'exe' Then $_FileGetSize = $_FileGetSize + FileGetSize ( $_Files2Attach[$x] ) / 1048576 ConsoleWrite ( "$_FileGetSize : " & $_FileGetSize & ' Mo' & @Crlf ) If $_FileGetSize < 10 Then $_ObjEmail.AddAttachment ( $_Files2Attach[$x] ) EndIf 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" ) = $_SmtpServer $_ObjEmail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ) = $_Port If $_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" ) = $_Username $_ObjEmail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/sendpassword" ) = $_Password EndIf If $_Ssl Then $_ObjEmail.Configuration.Fields.Item ( "http://schemas.microsoft.com/cdo/configuration/smtpusessl" ) = 1 $_ObjEmail.Configuration.Fields.Update $_ObjEmail.Send If @error Then SetError ( 2 ) Return $_MyRet[1] Else Return 1 EndIfEndFunc ;==> _SendEmailByGmail ( )
Func _GetExtByFullPath ( $_FullPath=@ScriptFullPath ) $_FileName = StringSplit ( $_FullPath, '.' ) If Not @error Then Return $_FileName[$_FileName[0]] Else Return 0 EndIf EndFunc ;==> _GetExtByFullPath ( )
Func _MyErrFunc ( ) $HexNumber = Hex ( $_MyError.Number, 8 ) $_MyRet[0] = $HexNumber $_MyRet[1] = StringStripWS ( $_MyError.description, 3 ) MsgBox ( 0, "### erreur d'envoie de la NotificaTon ", " ! Numéro: " & $HexNumber & " ligne du script & #058; " & $_MyError.scriptline & " Description:" & $_MyRet[1] & @LF, 20 ) SetError ( 1 ) ReturnEndFunc ;==> _MyErrFunc ( )
![Page 11: Macros, UDFs, Emails, Advanced Topics Week 8. Summary Last Lecture You should have your project idea now Projects due next week.](https://reader036.fdocuments.net/reader036/viewer/2022082818/56649e745503460f94b74c87/html5/thumbnails/11.jpg)
Let’s Talk about Projects
You guys are already skilledLook at Examples
Look at Forum
![Page 12: Macros, UDFs, Emails, Advanced Topics Week 8. Summary Last Lecture You should have your project idea now Projects due next week.](https://reader036.fdocuments.net/reader036/viewer/2022082818/56649e745503460f94b74c87/html5/thumbnails/12.jpg)
• You should have your project idea now• There will be two more classes just for help• Projects due last day of classes
![Page 13: Macros, UDFs, Emails, Advanced Topics Week 8. Summary Last Lecture You should have your project idea now Projects due next week.](https://reader036.fdocuments.net/reader036/viewer/2022082818/56649e745503460f94b74c87/html5/thumbnails/13.jpg)
Project Ideas
• Write a script that looks at websites listed in Excel and downloads all the faculty names/if people are registered
• Write a script that checks if you favorite class is filled.
• Write an alarm clock that plays your favorite song, or maybe checks if your browser is visiting facebook and force closes the tab after 5 minutes. Hide the tray icon so you can’t quit
![Page 14: Macros, UDFs, Emails, Advanced Topics Week 8. Summary Last Lecture You should have your project idea now Projects due next week.](https://reader036.fdocuments.net/reader036/viewer/2022082818/56649e745503460f94b74c87/html5/thumbnails/14.jpg)
Project Ideas
• Write a program for your grandma so she can use programs by clicking once.
• Write a program that fills out an online form.• Automate a facebook game and beat all your
friends high scores.• Do something that helps your homework or
research.• The possibilities are endless. Make yourself
more productive or more popular.