Exchange Web Services API: error sending message with application

I am trying to send a message with a PDF attachment using the EWS Managed API 2.0. I am sending email as an account, which is not mine, but for which I am sending as permissions.

I can send an email without an attachment, but as soon as I try to send an attachment, the request does not work.

The file definitely exists.

I have implemented TraceListener and I see that the Create Attachment request is sent when SendAndSaveCopy called, but I do not receive a proper response from the server (I know that the server receives my request, although, as an error, it is explicit from the server). I do not see a request to send an email message after the creation application crashes.

The error I get when trying to SendAndSaveCopy is equal to The request failed. The underlying connection was closed: An unexpected error occurred on a send. The request failed. The underlying connection was closed: An unexpected error occurred on a send. Internal exception Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.

I have googled this and in accordance with the fact that I have found several offers, I confirmed that this is not just a subscription timeout (the fact is supported, in the same context I can SendAndSaveCopy just fine without an attachment, as well as the fact that I can send an error message after the failure is just fine). Others indicated problems with the file size, but my file size is very small (151 KB).

My Exchange administrator checks to see if there is a server-side option that can affect this, but hasn't found anything yet.

Can someone tell me if they encountered (and found a solution) to this particular problem? Even any tips on specific settings that I could direct my Exchange administrator to?

My code is below (I deleted my graphs to print error messages for reading):

 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 
+4
source share
2 answers

From OP :

My Exchange administrator is monitoring a load balancer issue. If I connect directly to the exchange server, the problem disappears; but autodiscoverurl connects to the load balancer. Now he is following this. I hope that soon I will have a complete solution, but I thought that I would go further and publish in case it gives someone ideas or in case it helps someone else.

0
source

We have been in this for several months, and I do not think that we have ever come to the β€œright” solution to this. We tracked it to the Security Manager of applications enabled on the virtual IP address on F5. He looked at traffic and considered applications unsafe.

0
source

Source: https://habr.com/ru/post/1483376/


All Articles