Re: Bulk Emailer - Here it is!
Sorry about the zip. Here is the code:
Sorry about the zip. Here is the code:
Code:
function sendemail as c (e as p) '***********************************************************************************' 'PURPOSE: LOOP THROUGH A COLUMN OF EMAIL ADDRESSES AND SEND A CUSTOM MESSAGE TO ALL ' 'AUTHOR: MICHAEL VAUGHN ' 'EMAIL: [email protected] ' 'DATE: 02/01/2013 ' 'LICENSE: OPEN SOURCE ' '***********************************************************************************' DEBUG(1) ON ERROR GOTO ER dim nCount as N dim result as L dim pm as P dim ps as P dim ef as C = e.dataSubmitted.from dim es as C = e.dataSubmitted.subject dim em as C = e.dataSubmitted.message dim conn as SQL::Connection dim rs as SQL::ResultSet '=======================SQL CONNECT===================== IF conn.open("::NAME::XXXXXXX") THEN conn.PortableSQLEnabled = .t. conn.execute("SELECT DISTINCT add_email FROM appdata1") '** add_email is my column name rs = conn.ResultSet '** appdata1 is my table name END IF '=======================EMAIL LOOP====================== WHILE rs.nextrow() IF (email_smtp_open(ps, "smtp.gmail.com",465,"[email protected]","YOUR_PASSWORD","SSL")) THEN pm.from = alltrim(ef) pm.subject = alltrim(es) pm.message = alltrim(em) pm.to = alltrim(rs.Data("add_email")) '** Column Name IF *any(pm.to, "@")THEN 'save_to_file(pm.to + " " + crlf(),"c:\Email Addresses.txt",.t.) '** TOGGLE ON FOR TESTING result = email_smtp_send(pm, ps) '** TOGGLE OFF FOR TESTING FOR nCount = 1 to 5 '** Retry Send if needed IF result = .t. THEN EXIT FOR END IF result = email_smtp_send(pm, ps) '** TOGGLE OFF FOR TESTING NEXT nCount email_smtp_close(ps) '** TOGGLE OFF FOR TESTING SLEEP(2) '** Be nice to the server END IF END IF END WHILE conn.close() sendemail = "alert('Your task has completed');" exit function '=======================ERROR HANDLER=================== ER: sendemail = "alert('" + conn.CallResult.text + "');" '** If you see only "Success" there was a problem conn.close() '** within the loop email_smtp_close(ps) '** TOGGLE OFF FOR TESTING end function
Comment