Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.80 KB | None | 0 0
  1. Imports System.Net
  2. Imports System.Net.Http
  3. Imports System.Threading.Tasks
  4.  
  5. Public Class AS2MDNSender
  6.     Private uri As Uri
  7.     Private from As String
  8.     Private [to] As String
  9.     Private messageId As String
  10.  
  11.     Sub New(ByVal uri As Uri, ByVal from As String, ByVal [to] As String, ByVal messageId As String)
  12.         Me.uri = uri
  13.         Me.from = from
  14.         Me.to = [to]
  15.         Me.messageId = messageId
  16.     End Sub
  17.  
  18.     Sub send()
  19.         Threading.ThreadPool.QueueUserWorkItem(AddressOf SendMDN)
  20.     End Sub
  21.  
  22.     Private Function SendMDN() As HttpResponseMessage
  23.         Threading.Thread.Sleep(10000)
  24.         Using httpClient As New HttpClient
  25.             Using content = New MultipartContent("report")
  26.                 'content.Headers.TryAddWithoutValidation("Content-Type", "report-type=disposition-notification")
  27.                 content.Headers.Add("Message-Id", String.Format("<AS2_{0}@{1}>", Date.Now.ToString("yyyyMMddHHmmssfff"), "247"))
  28.                 content.Headers.Add("AS2-Version", "1.1")
  29.                 content.Headers.Add("AS2-From", from)
  30.                 content.Headers.Add("AS2-To", [to])
  31.  
  32.                 Dim contentText = "Receipt text"
  33.                 content.Add(New StringContent(contentText))
  34.  
  35.                 Dim contentHeaders = "Disposition: automatic-action/MDN-sent-automatically; processed" & vbNewLine &
  36.                     "Final-Recipient: rfc822; " & [to] & vbNewLine &
  37.                     "Original-Recipient: rfc822; " & [to] & vbNewLine &
  38.                     "Original-Message-ID: " & messageId & vbNewLine
  39.                 content.Add(New StringContent(contentHeaders, Encoding.UTF8, "message/disposition-notification"))
  40.  
  41.                 Return httpClient.PostAsync(uri, content).Result
  42.             End Using
  43.         End Using
  44.     End Function
  45. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement