【发布时间】:2016-08-22 13:26:36
【问题描述】:
我有一个 VB.NET 程序,它每天向 5 个外部收件人发送 4 个附件。每天这些附件的大小都是一样的,从 149KB 到 161KB 不等。
有些日子,该消息会从我们的交换服务器退回,并带有以下消息:
远程服务器返回 '550 5.2.3 RESOLVER.RST.SendSizeLimit.Org; 消息对于此组织来说太大了'
消息的大小应该是大约 160*4=640KB,但是反弹告诉我们:
此邮件过大,未发送给任何人。这 限制为 24 MB。此消息为 35 MB。
我们不确定,但 35 MB 的数字似乎是附件的总大小乘以所有 5 个收件人。
其他日子它发送良好。我们无法找到关于何时失败的模式——通常是每周 5 天中的 1-3 天。此外,如果我使用 blat 和批处理文件将相同的附件发送给相同的收件人,他们总是可以正确发送。
我们之前在另一台服务器上运行过这个程序(现在已经失效),它从来没有因为这条消息而失败。似乎该服务器有一些特定的东西干扰了电子邮件的发送方式,但我们不确定在哪里寻找。会不会是 .NET 程序和 blat 以某种方式进行交互?我不相信旧服务器已经安装了 blat。
我个人无法访问所有交换日志,但我让同事检查了它们,他们说他们找不到任何异常情况。
编辑代码:
Public Sub SendEmail()
Dim objMail As New SmtpClient(ConfigurationManager.AppSettings("MailServer").ToString, 25)
Dim objMess As MailMessage
Dim strBody As String
Dim JHPath As String : JHPath = ConfigurationManager.AppSettings("JHFiles").ToString
Try
'create a new message object
objMess = New Net.Mail.MailMessage()
objMail.Timeout = 90000 '90 seconds
'add sender to the message object
objMess.From = New MailAddress(ConfigurationManager.AppSettings("MailFromAddr"), "<redacted>")
'add recipients
For Each addr As String In ConfigurationManager.AppSettings("MailToAddr").Split(";")
objMess.To.Add(addr)
Next
'the body text of the email
strBody = ""
'add subject to the message object
objMess.Subject = "<redacted> " & labelsDate.ToString("MM/dd/yyyy") & " - " & <redacted>
'add body to the message object
objMess.Body = strBody
Dim filAge As Integer
'attach the 4 files necessary for the <redacted> - only today's
For Each fil As String In IO.Directory.GetFiles(JHPath)
filAge = (Today() - IO.File.GetLastWriteTime(fil)).Days
If filAge < 1 And Not (fil Like "*Thumbs.db") Then 'add today's files only, in case archiving did not happen
objMess.Attachments.Add(New Attachment(fil))
End If
Next
'send the email
Console.WriteLine(Now() & " -- Sending email..... " & vbCrLf)
writer.WriteLine(Now() & vbTab & "Sending email..... " & vbCrLf)
'try sending the message
Try
objMail.Send(objMess)
writer.WriteLine(Now() & vbTab & "Email sent and cleaned up. " & vbCrLf)
Catch ex As Exception
Dim mess As String : mess = Now() & " -- Failure sending email to <redacted>!"
Console.WriteLine(mess)
writer.WriteLine(mess)
Finally
'get rid of the message object, cleanup
objMess.Dispose()
End Try
Catch ex As Exception
Console.WriteLine(Now() & " -- Other Error Emailing to <redacted>: " & ex.Message)
writer.WriteLine(Now() & vbTab & "Exception while Emailing <redacted>: " & ex.Message & vbCrLf)
SendEmails("Error emailing <redacted>." & ex.Message & vbCrLf & ex.StackTrace)
End Try
End Sub
【问题讨论】:
-
如果不显示您的代码,我们无能为力(请记住在发布之前从任何密码和个人信息中删除代码)。
标签: vb.net exchange-server system.net.mail