I have a system that generates numerous PDF files and then sends each to specified recipients. The process usually works properly, but occasionally, one of the emails comes out completely garbled. It is as though something hiccuped during the email send process.
This is what gets sent:
The encoding mess goes on for quite a while, I just clipped a small sample.
It is not always with the same pdf file, it is not always to the same recipient.
The PDF's are all OK, and it just seems to be in the e-mail process.
This process runs automatically 4 times daily, and it really needs to be correct. It is making my customer rather nervous that the process isn't working 100% correctly.
Here is the routine that I use to build the PDF's and then mail them. Each report is built and saved to a specified folder, then I loop through a "client" table to send the appropriate PDF to the corresponding e-mail address.
I needed to put timing delays into the email routine so that the ISP didn't think I was spamming.
Is it Alpha, or the ISP?
If anyone has an idea, please let me know.
Thanks,
Tom
This is what gets sent:
Sent: Thursday, December 17, 2009 6:09 AM
To: [email protected]
Subject: Tobyhanna PA Pavement Condition Forcast
----=_C811abB4F6e6051E3705EEeb36BB0320F45bC2637a54D36b3332a32B0D62C6E0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Attached is the Pavement Condition Forcast for Tobyhanna PA
----=_C811abB4F6e6051E3705EEeb36BB0320F45bC2637a54D36b3332a32B0D62C6E0
Content-Type: application/pdf; name="Tobyhanna_PA_Pavement_forcast.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="Tobyhanna_PA_Pavement_forcast.pdf"
JVBERi0xLjMNJf////8NMSAwIG9iag08PA0vVGl0bGUgKP7/AEMAbwBuAGQAaQB0AGkAbwBu
ACAATABlAHQAdABlAHIAcykNL1Byb2R1Y2VyIChBbXl1bmkgUERGIENvbnZlcnRlciB2ZXJz
aW9uIDIuNTEtYikNL0NyZWF0aW9uRGF0ZSAoRDoyMDA5MTIxNzA1MzA0MykNPj4NZW5kb2Jq
DTcgMCBvYmoNPDwgL0xlbmd0aCA4IDAgUiAvRmlsdGVyIC9GbGF0ZURlY29kZSA+Pg1zdHJl
YW0KeF4zVDAAQkMFQzM9CyAjOZe3kDePy9jCWM/cDCxlbqRgYalnYKJgBhFLzuXS98y1VHDJ
To: [email protected]
Subject: Tobyhanna PA Pavement Condition Forcast
----=_C811abB4F6e6051E3705EEeb36BB0320F45bC2637a54D36b3332a32B0D62C6E0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Attached is the Pavement Condition Forcast for Tobyhanna PA
----=_C811abB4F6e6051E3705EEeb36BB0320F45bC2637a54D36b3332a32B0D62C6E0
Content-Type: application/pdf; name="Tobyhanna_PA_Pavement_forcast.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="Tobyhanna_PA_Pavement_forcast.pdf"
JVBERi0xLjMNJf////8NMSAwIG9iag08PA0vVGl0bGUgKP7/AEMAbwBuAGQAaQB0AGkAbwBu
ACAATABlAHQAdABlAHIAcykNL1Byb2R1Y2VyIChBbXl1bmkgUERGIENvbnZlcnRlciB2ZXJz
aW9uIDIuNTEtYikNL0NyZWF0aW9uRGF0ZSAoRDoyMDA5MTIxNzA1MzA0MykNPj4NZW5kb2Jq
DTcgMCBvYmoNPDwgL0xlbmd0aCA4IDAgUiAvRmlsdGVyIC9GbGF0ZURlY29kZSA+Pg1zdHJl
YW0KeF4zVDAAQkMFQzM9CyAjOZe3kDePy9jCWM/cDCxlbqRgYalnYKJgBhFLzuXS98y1VHDJ
It is not always with the same pdf file, it is not always to the same recipient.
The PDF's are all OK, and it just seems to be in the e-mail process.
This process runs automatically 4 times daily, and it really needs to be correct. It is making my customer rather nervous that the process isn't working 100% correctly.
Here is the routine that I use to build the PDF's and then mail them. Each report is built and saved to a specified folder, then I loop through a "client" table to send the appropriate PDF to the corresponding e-mail address.
I needed to put timing delays into the email routine so that the ISP didn't think I was spamming.
Code:
Dim text1 as C Dim a1[4] as C dim L as N dim M as N dim N as N Dim Skip as N text1 = get_from_file("C:\FORECAST\timing.txt") a1.initialize(text1) N = val(a1[1]) 'N is the number of e-mails to do in a batch L = val(a1[2]) 'L is the number of seconds to wait after each e-mail M = val(a1[3]) 'M is the number of seconds to wait between batches Skip = val(a1[4]) 'SKIP is the number of e-mails that had been sent in a previous attempt. ON ERROR goto ERROR_TEST 'usual error is SMTP timeout. Wait 90 seconds and try again dim tbl as P Dim tbl2 as P tbl = table.open("conditions") tbl2 = table.open("clients") 'goto skipit2 f1.write_line("Begin Build of Reports at "+time("h:mmAM")+" on "+date_format(date(),"Mon-d-yyyy")) dim J as N Dim loc as C J=0 loc = "" tbl.fetch_first() loc = tbl.Location while .not.tbl.fetch_eof() if exist(padr(trim(tbl.Location),35," "),"conditions","Location") pdf_filename = "C:\Forecast\reports"+chr(92)+trim(tbl.location)+"_Pavement_forcast.pdf" if file_exists(pdf_filename) file_remove(pdf_filename) end if filt1 = "location="+quote(trim(tbl.Location)) query.filter = filt1 query.order = "" 'report.preview("Condition Letters",query.filter,query.order) report.SaveAs("Condition Letters","PDF",query.filter,query.order,pdf_filename) end if tbl.fetch_next() while tbl.Location = loc .and..not.tbl.eof() tbl.fetch_next() end while loc = tbl.Location J=J+1 end while f1.write_line(alltrim(str(J-1))+" Reports Built by "+time("h:mmAM")+" on "+date_format(date(),"Mon-d-yyyy")) skipit2: f1.write_line("Begin E-mail of Reports at "+time("h:mmAM")+" on "+date_format(date(),"Mon-d-yyyy")) tbl2.index_primary_put("Location") tbl2.fetch_first() dim I as N dim K as N J=0 K=0 I=0 h = 0 'skip anty locations with a blank e-mail address. Skip the 1st [skip] reports while .not.tbl2.fetch_eof() if tbl2.Email_addr = "" statusbar.Set_Text("skipping email report "+strtran(trim(tbl2.location),"_"," ")) tbl2.fetch_next() else if Skip >0 while h < Skip tbl2.fetch_next() h = h+1 end while end if if I < N J=J+1 I=I+1 pdf_filename = "C:\Forecast\reports"+chr(92)+trim(tbl2.location)+"_Pavement_forcast.pdf" msg_text = "Attached is the Pavement Condition Forcast for "+strtran(tbl2.location,"_"," ") param_to = trim(tbl2.Email_addr) param_subject = alltrim(strtran(tbl2.location,"_"," "))+" Pavement Condition Forcast" param_cc = "" param_bcc = "" param_msg = msg_text param_attachments = pdf_filename ' traceln(alltrim(str(K+I))+" sending email report "+strtran(trim(tbl1.location),"_"," ")+" to "+trim(tbl1.Email_addr)) statusbar.Set_Text(alltrim(str(K+I))+" sending email report "+strtran(trim(tbl2.location),"_"," ")+" to "+trim(tbl2.Email_addr)) email_Send(param_to,param_subject,param_msg,param_attachments) tbl2.fetch_next() sleep(L) else statusbar.Set_Text("Sleeping for "+alltrim(str(M/60,5,2))+" minutes... DO NOT Disturb!") sleep(M) I=0 K=K+N 'tbl1.fetch_next() end if end if end while f1.write_line(alltrim(str(J))+" Reports Mailed by "+time("h:mmAM")+" on "+date_format(date(),"Mon-d-yyyy")) f1.write_line("*** End Build and e-mail of Reports at "+time("h:mmAM")+" on "+date_format(date(),"Mon-d-yyyy")) tbl2.close() tbl.close() endit: f1.close() f1.flush() 'end a5.Close() ERROR_TEST: 'wait for 90 seconds and then try the send again SLEEP(90) RESUME 0 end
If anyone has an idea, please let me know.
Thanks,
Tom
Comment