Foxtable(狐表)用户栏目专家坐堂 → [求助] 大容量文件邮件发放超时问题


  共有2522人关注过本帖树形打印复制链接

主题:[求助] 大容量文件邮件发放超时问题

帅哥哟,离线,有人找我吗?
2900819580
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1312 积分:9533 威望:0 精华:0 注册:2015/6/30 8:46:00
[求助] 大容量文件邮件发放超时问题  发帖心情 Post By:2018/8/15 14:56:00 [只看该作者]

以下是发邮件代码,文件比较小的时候可以正常发送,但文件比较大的时间,就发不出去,或者发送的时间很长。

 

 

Dim m As New MailSender
m.Host = "smtp.163.com" '用于指定主机地址,可以是域名,也可以是IP地址.
m.Account = "8888" '用于指定登录邮件服务器的帐号
m.Password = "88888" '用于指定登录邮件服务器的密码
m.From = "88888@163.com" '用于指定发件人的邮件地址
m.AddReceiver(e.Form.Controls("Text_邮箱").text)'于指定收件人的邮件地址
m.AddReceiver("888888888@163.com")
m.Title = e.Form.Controls("Txt_Title").text
m.Content = e.Form.Controls("Txt_Content").text
If r.IsNull("电子档文件") = False Then m.AddAttachments(Vars("OAPath") & "文控中心\受控文件\" & r("文件种类") & "\电子文件\" &  r("电子档文件"))
If r("发放形式") = "发放" Then
    m.AddAttachments(Vars("OAPath") & "文控中心\受控文件\" & r("文件种类") & "\" & r("文件编号") & " " & r("文件名称") & ".pdf")
Else
    m.AddAttachments(Vars("OAPath") & "文控中心\作废文件\" & r("文件种类") & "\" & r("文件编号") & " " & r("文件名称") & ".pdf")
End If

m.Send()

MessageBox.Show("发送成功")


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/8/15 15:23:00 [只看该作者]

设置超时时间

 

Dim client As New System.Net.Mail.SmtpClient()
client.timeout = 1000 '1秒
client.Host = "smtp.qq.com"
client.Credentials = New System.Net.NetworkCredential("455189993@qq.com", "helen6849338.")
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
Dim message As New System.Net.Mail.MailMessage
message.From = new System.Net.Mail.MailAddress("455189993@qq.com")
message.To.Add("765427475@qq.com")

'message.Bcc.Add("2450314695@qq.com") '密送

'message.cc.Add("2450314695@qq.com") '抄送

Dim content As String

content &= "这是文字" & vbcrlf
content &= "也是文字"

message.Body = content

Dim attachment As new  System.Net.Mail.Attachment("d:\test.xls",  System.Net.Mime.MediaTypeNames.Application.Octet)
message.Attachments.Add(attachment)

Try
    client.Send(message)
    msgbox("发送成功")
Catch ex As Exception
    msgbox("发送失败:" & ex.message)

finally

    message.Dispose()
End Try

 


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/8/15 15:24:00 [只看该作者]


 回到顶部
帅哥哟,离线,有人找我吗?
2900819580
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1312 积分:9533 威望:0 精华:0 注册:2015/6/30 8:46:00
  发帖心情 Post By:2018/8/15 16:16:00 [只看该作者]

老师,附件在那里增加,如果用异步发送的话,是不是就不用考虑超时时间的问题了。

 

 

Dim client As New Net.Mail.SmtpClient("smtp.126.com")
'client.Timeout = 60000

client.UseDefaultCredentials = True
client.Credentials = new System.Net.NetworkCredential("lin_hailun@126.com", "6849338.")
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network

Dim [from] As New Net.Mail.MailAddress("lin_hailun@126.com", "lin " & ChrW(&HD8) & " hailun", System.Text.Encoding.UTF8)
' Set destinations for the e-mail message.
Dim [To] As New Net.Mail.MailAddress("2450314695@qq.com")
' Specify the message content.
Dim message As New Net.Mail.MailMessage([from], [To])

message.Body = "This is a test e-mail message sent by an application. "
' Include some non-ASCII characters in body and subject.
Dim someArrows As New String(New Char() {ChrW(&H2190), ChrW(&H2191), ChrW(&H2192), ChrW(&H2193)})
message.Body += Environment.NewLine & someArrows
message.BodyEncoding = System.Text.Encoding.UTF8
message.Subject = "test message 1" & someArrows
message.SubjectEncoding = System.Text.Encoding.UTF8
' Set the method that is called back when the send operation ends.
AddHandler client.SendCompleted, AddressOf SendCompletedCallback

Dim userState As String = "test message1"
client.SendAsync(message, userState)


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/8/15 16:46:00 [只看该作者]

一样要设置 client.Timeout = 60000 的,你可以设置成较大的值。

 

 


 回到顶部
帅哥哟,离线,有人找我吗?
2900819580
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1312 积分:9533 威望:0 精华:0 注册:2015/6/30 8:46:00
  发帖心情 Post By:2018/8/16 9:09:00 [只看该作者]

老师,附件在那里增加

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/8/16 9:35:00 [只看该作者]

以下是引用2900819580在2018/8/16 9:09:00的发言:
老师,附件在那里增加

 

参考2楼代码

 

Dim attachment As new  System.Net.Mail.Attachment("d:\test.xls",  System.Net.Mime.MediaTypeNames.Application.Octet)
message.Attachments.Add(attachment)


 回到顶部
帅哥哟,离线,有人找我吗?
2900819580
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1312 积分:9533 威望:0 精华:0 注册:2015/6/30 8:46:00
  发帖心情 Post By:2018/8/16 10:52:00 [只看该作者]

老师,测试过30多M的附件可以正常发送,但目前有些文件大于100M的,以下代码没有办法知道是否发送成功;

 

问题:如果发送失败,怎么样可以返鐀信息回来。

 

Dim tb As Table = Tables("受控文件管理" & "_Table1")
Dim r As Row = tb.Current
e.Form.Controls("But生成内容").performclick
e.Sender.Enabled = False
Dim path As String,path1 As String

If r("发放形式") = "发放" Then
    If r.IsNull("电子档文件") = False Then path = (Vars("OAPath") & "文控中心\受控文件\" & r("文件种类") & "\电子文件\" &  r("电子档文件"))
    path1 = (Vars("OAPath") & "文控中心\受控文件\" & r("文件种类") & "\" & r("文件编号") & " " & r("文件名称") & ".pdf")
Else
    MessageBox.Show("不能发送已经回收的受控文件")
    Exit Sub
End If
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~?
e.Sender.Enabled = False
e.Form.Controls("PictureBox1").Visible = True
e.Form.Controls("LabSend").Visible = True
Application.DoEvents()
MessageBox.Show("开始发送……………………")
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~?
Dim client As New Net.Mail.SmtpClient("smtp.163.com")
client.Timeout = 120000 '延时设置
client.UseDefaultCredentials = True
client.Credentials = new System.Net.NetworkCredential("000000@163.com", "00000000")
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network

Dim [from] As New Net.Mail.MailAddress("000000@163.com", "000000 " & ChrW(&HD8) & " 采购部", System.Text.Encoding.UTF8)
' Set destinations for the e-mail message.
Dim [To] As New Net.Mail.MailAddress(e.Form.Controls("Text_邮箱").text)

' Specify the message content.
Dim message As New Net.Mail.MailMessage([from], [To])
message.cc.Add("0000000@163.com") '抄送
message.Body = e.Form.Controls("Txt_Content").text
' Include some non-ASCII characters in body and subject.

message.Body += Environment.NewLine ' & someArrows
message.BodyEncoding = System.Text.Encoding.UTF8
message.Subject = e.Form.Controls("Txt_Title").text ' & someArrows
message.SubjectEncoding = System.Text.Encoding.UTF8
' Set the method that is called back when the send operation ends.
'AddHandler client.SendCompleted, AddressOf SendCompletedCallback
'~~~~~~~~~~~~~~~~~~~~ 发送附档文件~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim attachment As new  System.Net.Mail.Attachment(path1,  System.Net.Mime.MediaTypeNames.Application.Octet)
message.Attachments.Add(attachment)
Dim attachment1 As new  System.Net.Mail.Attachment(path,  System.Net.Mime.MediaTypeNames.Application.Octet)
message.Attachments.Add(attachment1)
AddHandler client.SendCompleted, AddressOf SendCompletedCallback
'~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim userState As String = e.Form.Controls("Txt_Title").text
client.SendAsync(message, userState)
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~·
MessageBox.Show("发送成功,请关闭窗口")


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/8/16 11:09:00 [只看该作者]


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  10楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/8/16 11:10:00 [只看该作者]

全局代码那里放回结果

 

Public Sub SendCompletedCallback(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
' Get the unique identifier for this asynchronous operation.
Dim token As String = CStr(e.UserState)

If e.Cancelled Then
    output.show("[" & token & "] Send canceled.")
End If
If e.Error IsNot Nothing Then
    output.show("[{" & token & "}] {" & e.Error.ToString() & "}" )
Else
    output.show("Message sent.")
End If

End Sub


 回到顶部