问题描述
- PB 使用JMAIL, timer事件 循环发送邮件 死机 哪位高手看下代码有啥问题?
- 开始使用Mymail.dll ,发送邮件(在timer事件写的发送,即发现有附件即触发发送函数) 一切正常,程序后台运行几周都没问题,后来看见网上说jmail.dll 比mymail.dll好用,就讲程序改用调jmail.dll后,自动执行2天 基本程序就死在那了,资源管理器发下,程序内存占用增长了不少,不知道什么原因 ,哪位高手给指点一下,谢谢
1、定义窗口级别 实例 OLE对象
oleobject lole-jmail
2、定义窗口open 事件creat
String ls_useridls_passwordls_sender
Long ll_net
lole_jmail = Create oleobjectls_userid=uo_send_info.sle_user.text
ls_password=uo_send_info.sle_pass.text
ls_sender = uo_send_info.sle_sender.textll_net = lole_jmail.ConnectToNewObject(""Jmail.Message"")
If ll_net = 0 Then
lole_jmail.Charset=""gb2312""
lole_jmail.Encoding=""base64""//
lole_jmail.ContentTransferEncoding = ""base64""//
lole_jmail.ISOEncodeHeaders=true
lole_jmail.silent=true
lole_jmail.Logging=true
lole_jmail.From=ls_sender
lole_jmail.FromName=""有限公司""//ls_userid // 发件人姓名
lole_jmail.MailServerUserName=ls_sender
lole_jmail.MailServerPassword=ls_password // 发件邮箱用户密码
end if3、在timer 事件 执行 发送函数
of_send(),该函数 5秒执行一次,程序运行2天 基本都死掉,估计问题在这里。。。
核心函数代码如下:
String ls_host
String ls_readyls_finishedls_isattachls_flagls_subjectls_bodyls_origpathls_origfilels_orig
String ls_recipientlsa_recipient[]
Long ll_cntijkll_netgb_running = True
ll_cnt = dw_send.RowCount()
If ll_cnt<=0 Then
MessageBox(""系统提示""请先配置收件人地址!"")
Return -1
End Ifls_host=uo_send_info.sle_host.text
If IsValid(lole_jmail) Then
For i = 1 To ll_cnt
ls_ready = Trim(dw_send.GetItemString(iready""))
ls_finished = Trim(dw_send.GetItemString(ifinished""))
ls_isattach = Trim(dw_send.GetItemString(iisattach""))
ls_flag = Trim(dw_send.GetItemString(iflag""))
ls_recipient = Trim(dw_send.GetItemString(irecipient""))
ls_subject = Trim(dw_send.GetItemString(isubject""))
ls_body = Trim(dw_send.GetItemString(ibody""))
ls_origpath = Trim(dw_send.GetItemString(iorigpath""))
ls_origfile = Trim(dw_send.GetItemString(iorigfile""))
ls_orig = ls_origpath+ls_origfileIf ls_flag = 'n' Then Continue; If as_repeat = ""n"" Then If ls_finished = 'y' Then Continue; End If If ls_ready = 'y' Then gf_string2array(ls_recipient';'lsa_recipient[]) // 收件人 lole_jmail.ClearRecipients() For j = 1 to upperbound(lsa_recipient[]) If pos(lsa_recipient[j]'@')>0 Then lole_jmail.AddRecipient(lsa_recipient[j]) End If Next lole_jmail.Subject=ls_subject lole_jmail.Priority=3 // 优先级 lole_jmail.Body=ls_body //邮件内容 // 附件 If ls_isattach = 'y' Then For k = 1 to 1 //只有一个附件 //lole_jmail.addattachment(plb_attachment.text(i)) lole_jmail.ClearAttachments() lole_jmail.addattachment(ls_orig) Next End If If lole_jmail.Send(ls_host) Then mle_1.text=Trim(mle_1.text)+""发送成功: [""+ls_origfile + ""]: ""+""~r~n"" gf_writelog(""发送成功: [""+ls_origfile + ""]"") If Not of_save_send_log(ls_origfilels_recipient) Then mle_1.text=Trim(mle_1.text)+""保存log失败: [""+ls_origfile + ""]: ""+""~r~n"" gf_writelog(""保存log失败: [""+ls_origfile + ""]"") End If Else mle_1.text=Trim(mle_1.text)+""发送失败: [""+ls_origfile + ""]: ""+""~r~n"" gf_writelog(""发送失败: [""+ls_origfile + ""]"") End if End IfNext
End If
gb_running = False
Return 1