vb.net - Exchange Web 服务 API : Error Sending Message with Attachment

标签 vb.net exchangewebservices email-attachments ews-managed-api

我正在尝试使用 EWS Managed API 2.0 发送带有 PDF 附件的消息。我发送的电子邮件不是我自己的帐户,但我已作为其发送权限。

我可以发送没有附件的电子邮件,但是一旦我尝试发送附件,请求就会失败。

该文件肯定存在。

我已经实现了 TraceListener并看到在 SendAndSaveCopy 时发送了 Create Attachment 请求被调用,但我没有从服务器收到正确的响应(我知道服务器正在收到我的请求,因为错误显然来自服务器)。在创建附件似乎失败后,我没有看到发送电子邮件的请求。

我在尝试 SendAndSaveCopy 时收到的错误是 The request failed. The underlying connection was closed: An unexpected error occurred on a send.内部异常是 Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.
我已经用谷歌搜索了这个,根据我发现的一些建议,我已经确认这不仅仅是订阅超时(在完全相同的上下文中,我可以在没有附件的情况下使用 SendAndSaveCopy 就可以了,并且还通过事实上我可以在失败后发送错误电子邮件就好了)。其他人提到了文件大小问题,但我的文件大小非常小 (151 KB)。

我的 Exchange 管理员正在检查服务器端是否有可能影响此设置但尚未发现任何设置。

谁能告诉我他们是否遇到过(并找到了解决方案)这个特定问题?甚至我可以指导我的 Exchange 管理员查看有关特定设置的任何提示?

我的代码附在下面(为了可读性,我已经删除了错误消息打印的gobs):

Public Function SendEmailResponse(ByVal strSender As String, ByVal strRecipient As String, ByVal strSubject As String, ByVal strBody As String, _
                        ByVal ews2010 As ExchangeService, Optional ByVal strCCAddresses As List(Of String) = Nothing, _
                        Optional ByVal strFilesToAttach As List(Of String) = Nothing, _
                        Optional ByVal blnReceipt As Boolean = False) As Boolean
    Try
        Dim msgReply As New EmailMessage(ews2010)
        msgReply.Subject = strSubject
        msgReply.Body = New MessageBody(BodyType.Text, strBody)
        Dim fromAddress As New EmailAddress(strSender)
        msgReply.From = fromAddress
        msgReply.ToRecipients.Add(strRecipient)
        msgReply.IsReadReceiptRequested = blnReceipt
        If strCCAddresses IsNot Nothing Then
            For Each strCC As String In strCCAddresses
                msgReply.CcRecipients.Add(strCC)
            Next
        End If
        msgReply.Save()  '''This works just fine

        If strFilesToAttach IsNot Nothing Then
            For Each flAttach In strFilesToAttach
                msgReply.Attachments.AddFileAttachment(flAttach)
            Next
        End If
        msgReply.SendAndSaveCopy() '''CRASHES HERE IF AND ONLY IF I've attached files in the above loop
        SendEmailResponse = True
    Catch ex As Exception
        SendEmailResponse = False
    End Try
End Function

最佳答案

From the OP :

My Exchange administrator has tracked down the problem to the load balancer somehow. If I connect directly to the exchange server the problem vanishes; but the autodiscoverurl connects to the load balancer. He's following up on that now. Hopefully I'll have a complete solution up soon, but thought I'd go ahead and post in case this gives anyone any ideas or in case it helps someone else.

关于vb.net - Exchange Web 服务 API : Error Sending Message with Attachment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16816892/

相关文章:

android - 如何将 ImageView 附加为电子邮件附件?

c# - C# 和 VB.NET 中的文件路径(通过 WCF)

vb.net通过面板控件将图像分配给picturebox

sql - SELECT * FROM MyTable WHERE [日期] = ([日期] + 8 小时)

c# - 带有复选框的 asp.net 下拉列表

c# - EWS 托管 API 1.1 - 拉取订阅内存泄漏

c# - 使用 Exchange Web 服务 (EWS) API 查找 Exchange Server 版本的方法

php - 使用 SwiftMailer 从 Web 表单上传的电子邮件附件

c# - EWS 消息跟踪报告

ruby-on-rails - 如何创建多部分电子邮件? [ rails ]