Jump to content
Sign in to follow this  
cybie

Automatic Affiliate Email Generator

Recommended Posts

cybie

Okay, although I have used AutoIt to make little scripts to catch popups and other minimal things, this is my first elaborate attempt at somthing that makes my job easier.

The reason I made this script was because I frequently send a custom email to new individuals who sign up with us. I send the email to detail how to link to us, and include custom-coded HTML pages that they can implement on their own site.

The emails and the HTML files included must contain a special code in the links back to our site for identification purposes, which is why the pages must be customized.

This AU3 is set up to require 3 template pages that will require a replacement in their content prior to sending, one page that will remain static and a splash screen image that will display when you start the script (not important). You will need to adjust this to meet your needs, and I hope someone finds it useful to email new members or whoever you like.

This is INCREDIBLY dependant on your computer having the same version of MS office installed that I have. There is a way to work around this and make it find the program, but I couldn't get it to work. Also, sometimes the program de-rails when it gets into MS Word... I'm not sure why...

Here's the code:

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Platform:       WinXP
; Author:         Cybie
;
; Script Function:
;   Copy template HTML files, replace selected content and send the files via email using MS Word.
;
; ----------------------------------------------------------------------------
AutoItSetOption ( "RunErrorsFatal", 0 );set run failure to return 1

; Press Esc to terminate script, Pause/Break to "pause"
Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
; ----------------------------------------------------------------------------
; Install files into exe.
; ----------------------------------------------------------------------------
$splash = @TempDir & "splash.jpg"
FileInstall("splash.jpg", $splash, 1)

$content = @TempDir & "\content.html"
FileInstall("content.html", $content, 1)

$banners = @TempDir & "\banners.html"
FileInstall("banners.html", $banners, 1)

$email = @TempDir & "\affiliate-linking-email.html"
FileInstall("affiliate-linking-email.html", $email, 1)

$images = @TempDir & "\images.html"
FileInstall("images.html", $images, 1)



; ----------------------------------------------------------------------------
; Prompt for Producer Number
; ----------------------------------------------------------------------------
SplashImageOn("Splash Screen", $splash, 400, 200, -1, -1, 1)
Sleep(1000)
SplashOff()

$input = InputBox("Affiliate Email Generator", "Enter replacement info:", "?????", "", -1, -1)
;Creates an input box for new data to replace the ????? - the ????? is the information in your files that will be replaced.
If @error = 1 Then
   Exit
EndIf

; ----------------------------------------------------------------------------
; Create directory, copy files to it, switch to that directory
; ----------------------------------------------------------------------------
$scriptdir = @ScriptDir;variable for current directory

DirCreate ( $scriptdir & "\" & $input )

$InstallDir = $scriptdir & "\" & $input

FileCopy( $content, $InstallDir)
FileCopy( $banners, $InstallDir)
FileCopy( $email, $InstallDir)
FileCopy( $images, $InstallDir)
FileChangeDir( $InstallDir )

; ----------------------------------------------------------------------------
; Find and replace ????? with the proper producer number
; ----------------------------------------------------------------------------

$szFile = "content.html"
$szText = FileRead($szFile,FileGetSize($szFile))
$szText = StringReplace($szText, "?????", $input)
FileRecycle($szFile)
FileWrite($szFile,$szText)

$szFile2 = "banners.html"
$szText2 = FileRead($szFile2,FileGetSize($szFile2))
$szText2 = StringReplace($szText2, "?????", $input)
FileRecycle($szFile2)
FileWrite($szFile2,$szText2)

$szFile3 = "affiliate-linking-email.html"
$szText3 = FileRead($szFile3,FileGetSize($szFile3))
$szText3 = StringReplace($szText3, "?????", $input)
FileRecycle($szFile3)
FileWrite($szFile3,$szText3)

$szFile4 = "images.html"

; ----------------------------------------------------------------------------
; Open in word & begin progress bar
; ----------------------------------------------------------------------------

$msword = MsgBox ( 36, "Affiliate Page Generator", "Proceed to MS Word Email?" , 10 )
If $msword = -1 Then
   Exit
ElseIf $msword = 7 Then
  Run("explorer " & $InstallDir) 
   Exit
Else
EndIf

ProgressOn("Affiliate Email Generator", "", "0 percent", -1, -1, 16)
ProgressSet(0 , "Percentage Complete", "Please Wait...")

Run ("C:\Program Files\Microsoft Office\Office10\winword.exe")
If @error = 1 Then
   MsgBox (0, "Affiliate Page Generator", "MS Word could not be found on your system." @CR "Displaying directory contents instead." )
   Run("explorer " & $InstallDir) ;proper directory
     Exit
EndIf
WinWaitActive("Document")
;========VERY problematic part of the script. - Word sucks.
Send("{ALTDOWN}o{ALTUP}")
WinWaitActive("Open")
ClipPut ( @WorkingDir & "\" & $szFile3)
Send( "{CTRLDOWN}v{CTRLUP}" & "{ENTER}" )
WinWaitActive($szFile3)

ProgressSet(25 , "Percentage Complete", "Please Wait...")
; ----------------------------------------------------------------------------
; Open email dialog & attach files
; ----------------------------------------------------------------------------
Send("{ALTDOWN}fdm{ALTUP}")
Send("{ALTDOWN}il{ALTUP}")
WinWaitActive("Insert File")
ClipPut ( @WorkingDir & "\" & $szFile)
Send( "{CTRLDOWN}v{CTRLUP}" & "{ENTER}" )

ProgressSet(50 , "Percentage Complete", "Please Wait...")

Send("{ALTDOWN}il{ALTUP}")
WinWaitActive("Insert File")
ClipPut ( @WorkingDir & "\" & $szFile2)
Send( "{CTRLDOWN}v{CTRLUP}" & "{ENTER}" )

ProgressSet(75 , "Percentage Complete", "Please Wait...")

Send("{ALTDOWN}il{ALTUP}")
WinWaitActive("Insert File")
ClipPut ( @WorkingDir & "\" & $szFile4)
Send( "{CTRLDOWN}v{CTRLUP}" & "{ENTER}" )

ProgressSet(100 , "100% Complete", "Finished")

ProgressOff()

WinWaitClose ( $szFile3 )

; ----------------------------------------------------------------------------
; Open Excel for notes and Exit.
; ----------------------------------------------------------------------------
If WinExists ("Affiliate-Link-Emails") Then
  WinActivate ( "Affiliate-Link-Emails" )
ElseIf @Error = 0 Then
;=============
   $msexcel = MsgBox ( 36, "Affiliate Page Generator", "Note Excel Sheet for Producer " & $input & " ?", 10 )
   If $msexcel = -1 Then
      Exit
   ElseIf $msexcel = 7 Then
      Exit
   Else
   EndIf
;=============
   Run ("C:\Program Files\Microsoft Office\Office10\excel.exe C:\Affiliate-Link-Emails.xls")
   If @error = 1 Then
      MsgBox (0, "Affiliate Page Generator", "Excel could not be found on your system" @CR "displaying directory instead." & $input)   
      Run("explorer " & $InstallDir)  
     Exit
   EndIf
Else
EndIf

; ----------------------------------------------------------------------------
; Functions
; ----------------------------------------------------------------------------
Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

I believe I got the string replacement code from Larry's response to "Need help replacing text, Replace text in external file". :idiot:


Writing damaged code since 1996.

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.