Sending raw text in .Net API is yielding message with no item attached

  • 1
  • Question
  • Updated 2 weeks ago
I am attempting to send raw text using EncryptedEmails.Upload2, but the resulting message shows no text and no item attached. 

Private Sub sbSendEmail(p_objEmailTos As List(Of System.Net.Mail.MailAddress),
                            p_objEmailCCs As List(Of System.Net.Mail.MailAddress),
                            p_objEmailBCCs As List(Of System.Net.Mail.MailAddress),
                            p_strSubject As String,
                            p_strBody As String)
        Dim objShareFileClient As New ShareFileClient(m_cstr_SHAREFILE_BASE_URI)
        Dim objAuthService As New Security.Authentication.OAuth2.OAuthService(objShareFileClient, m_cstr_CLIENT_ID, m_cstr_CLIENT_SECRET)
        Dim objAuthToken As Security.Authentication.OAuth2.OAuthToken = objAuthService.GetPasswordGrantRequestQuery(m_cstr_SHAREFILE_USERNAME, m_cstr_SHAREFILE_PASSWORD, m_cstr_SHAREFILE_SUBDOMAIN, m_cstr_APPLICATION_CONTROL_PLANE).Execute
        objShareFileClient.AddOAuthCredentials(objAuthToken)
        objShareFileClient.BaseUri = objAuthToken.GetUri

        Dim objEncryptedEmailCreateParams As New Models.EncryptedEmailCreateParams

        Dim objTosPrincipalList As New List(Of Models.Principal)
        For Each objAddress As System.Net.Mail.MailAddress In p_objEmailTos
            Dim objPrincipal As New Models.Principal
            objPrincipal.Email = objAddress.Address
            objPrincipal.Name = objAddress.DisplayName
            objTosPrincipalList.Add(objPrincipal)
        Next
        objEncryptedEmailCreateParams.ToRecipients = objTosPrincipalList

        Dim objCCsPrincipalList As New List(Of Models.Principal)
        For Each objAddress As System.Net.Mail.MailAddress In p_objEmailCCs
            Dim objPrincipal As New Models.Principal
            objPrincipal.Email = objAddress.Address
            objPrincipal.Name = objAddress.DisplayName
            objCCsPrincipalList.Add(objPrincipal)
        Next
        objEncryptedEmailCreateParams.CcRecipients = objCCsPrincipalList

        Dim objBCCsPrincipalList As New List(Of Models.Principal)
        For Each objAddress As System.Net.Mail.MailAddress In p_objEmailBCCs
            Dim objPrincipal As New Models.Principal
            objPrincipal.Email = objAddress.Address
            objPrincipal.Name = objAddress.DisplayName
            objBCCsPrincipalList.Add(objPrincipal)
        Next
        objEncryptedEmailCreateParams.BccRecipients = objBCCsPrincipalList

        objEncryptedEmailCreateParams.Subject = p_strSubject
        objEncryptedEmailCreateParams.RequireLogin = True

        Dim objEncryptedEmail As Models.EncryptedEmail = objShareFileClient.EncryptedEmails.Create(objEncryptedEmailCreateParams).Execute

        Dim objUploadRequestParams As New Models.UploadRequestParams
        objUploadRequestParams.Raw = True
        objUploadRequestParams.FileName = "message.txt"
        objUploadRequestParams.FileSize = 0
        objUploadRequestParams.Method = Models.UploadMethod.Standard

        Dim objUploadSpecificationResponse As Models.UploadSpecification = objShareFileClient.EncryptedEmails.Upload2(objEncryptedEmail.url, objUploadRequestParams, 1).Execute

        Dim objHTTPWebRequest As HttpWebRequest = HttpWebRequest.Create(objUploadSpecificationResponse.ChunkUri)
        objHTTPWebRequest.Method = "POST"
        objHTTPWebRequest.ContentLength = p_strBody.Length

        Dim objStream As IO.Stream = objHTTPWebRequest.GetRequestStream()
        Dim objBytes() As Byte = New System.Text.UTF8Encoding().GetBytes(p_strBody)
        objStream.Write(objBytes, 0, objBytes.Length)
        Dim objWebResponse As WebResponse = objHTTPWebRequest.GetResponse

        Dim objEncryptedEmailSendParams As New Models.EncryptedEmailSendParams()
        Dim objItem As New Models.Item
        objItem.Id = System.Web.HttpUtility.ParseQueryString(objWebResponse.ResponseUri.Query)("uploadid")
        objEncryptedEmailSendParams.Message = objItem

        objShareFileClient.EncryptedEmails.Send(objEncryptedEmail.url, objEncryptedEmailSendParams).Execute()
    End Sub
Photo of Jeremy Sutka

Jeremy Sutka

  • 20 Posts
  • 1 Reply Like

Posted 2 weeks ago

  • 1

Be the first to post a reply!