I need a script that will parse/loop through a CSV or TXT file and (if there are rows) **remove duplicate emails** and **individually email** each person using our SMTP server.
It must then delete the CSV file, log success/failed transactions and send me an email alert.
Everyday, one of our Desktop Apps drops a CSV (or TXT file if it's easier) with the same name in a folder.
Inside the CSV file are 4 columns: **Appt Date, Patient Name**, **EmailAddress**, **Doctor**.
Some days the file is empty.
Other days, the file can have between 10-50 rows of people.
The CSV file is output by a desktop app and always looks the same (same 4 lines of headers and 1 line of footer).
I need a script that will parse/loop through the CSV file and (if there are rows) **remove duplicate emails** and **individually email** each person the following statement using our in-house SMTP Server:
> "Dear [FirstName] [Lastname] *(dynamically inserted from CSV file)*,
> Thanks for visiting our office on [Appt Date] *(dynamically inserted from CSV file)*. Please visit the link below to complete a brief survey.
> [[url removed, login to view]]
> [Doctor] *(dynamically inserted from CSV file)*"
Once the script is done emailing, it will delete the original CSV file and log all success/fail email transactions to a TXT log file in the same folder with the current date as the filename (ie, [url removed, login to view]).
Finally, the script will send me a "success" or "fail" email alert to a specific email address "[itdepartment@[url removed, login to view]]". If possible, I'd like to receive the exact error received on failures.
The only 3 accepted programming languages are ASP, PHP and Coldfusion. It's Windows 2003 with IIS, Coldfusion 8 & PHP 5 installed. I do not want a Windows Service or Desktop App.
**More Supplemental Details**
* The code must be well-commented. Just tell me what each section is doing in the code.
* If you can declare variables at the top, that would be great. I will need variables for **"From" Name**, **"From" Email Address**, **Email Subject** and "**BCC**" in outgoing "loop" emails **and** my alert emails.
* Our server is Windows 2003 with IIS, Coldfusion 8 & PHP 5 installed.
* I plan to use WGET (Windows CRON) or a Scheduled Task to trigger the script twice a day at specific times.
You can download a copy of the CSV/TXT File here:
**[url removed, login to view]**
It will always look like that...except on Saturdays and Sundays there will be no records/rows.