问题补充:现在的状态时循环发送50封信,如果第二封没有发送成功,后面的48封都没法发送。现在要机器重启才能
解决问题,请高手指点
Private Sub Form_Load()
Form1.Visible = True
For i = 1 To 50
Call sendM("NJ TEST" & i, "<center>Receive Email OK<hr>Description :LLLL<center>")
Next
Unload Me
End Sub
Public Function sendM(title As String, content As String)
Dim sFile As String
Dim flag_num
flag_num = 0
sendM:
On Error Resume Next
Set JMail = CreateObject("JMail.Message")
JMail.Charset = "gb2312"
JMail.From = "[email protected]"
JMail.subject = title
JMail.MailServerUserName = "[email protected]"
JMail.MailServerPassword = "1234"
JMail.Priority = 1
JMail.AddRecipient ("[email protected]")
'JMail.AddAttachment (sFile)
'content ="<center>Receive Email Error<hr>Description :" & errInfo & "<center>"
JMail.HTMLBody = content
JMail.Body = "我们的邮件采用了HTML格式,但是您的邮件查看软件可能不支持。"
flag = JMail.Send("smtp.excelpoint.com.cn")
If (flag) Then
Else
flag_num = flag_num + 1
If (flag_num = 5) Then
Else
'延迟一段时间
waittime (60)
GoTo sendM
End If
End If
Set JMail = Nothing
End Function
Public Sub waittime(delay As Single)
Dim starttime As Single
starttime = Timer
Do Until (Timer - starttime) > delay
DoEvents
Loop
End Sub
解决问题,请高手指点
Private Sub Form_Load()
Form1.Visible = True
For i = 1 To 50
Call sendM("NJ TEST" & i, "<center>Receive Email OK<hr>Description :LLLL<center>")
Next
Unload Me
End Sub
Public Function sendM(title As String, content As String)
Dim sFile As String
Dim flag_num
flag_num = 0
sendM:
On Error Resume Next
Set JMail = CreateObject("JMail.Message")
JMail.Charset = "gb2312"
JMail.From = "[email protected]"
JMail.subject = title
JMail.MailServerUserName = "[email protected]"
JMail.MailServerPassword = "1234"
JMail.Priority = 1
JMail.AddRecipient ("[email protected]")
'JMail.AddAttachment (sFile)
'content ="<center>Receive Email Error<hr>Description :" & errInfo & "<center>"
JMail.HTMLBody = content
JMail.Body = "我们的邮件采用了HTML格式,但是您的邮件查看软件可能不支持。"
flag = JMail.Send("smtp.excelpoint.com.cn")
If (flag) Then
Else
flag_num = flag_num + 1
If (flag_num = 5) Then
Else
'延迟一段时间
waittime (60)
GoTo sendM
End If
End If
Set JMail = Nothing
End Function
Public Sub waittime(delay As Single)
Dim starttime As Single
starttime = Timer
Do Until (Timer - starttime) > delay
DoEvents
Loop
End Sub
解决:
要修改sendM里的On Error Resume Next为 On Error goto a0 ,去掉goto返回,避免死循环
如果非要保留goto返回,至少也要加个条件判断,如果返回3次发送都不成功,就跳出
你没有看到我的代码里有个flag_num变量
以后用Winsock时候,再请教你.