Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Net
- Imports System.Net.Http
- Imports System.Threading.Tasks
- Public Class AS2MDNSender
- Private uri As Uri
- Private from As String
- Private [to] As String
- Private messageId As String
- Sub New(ByVal uri As Uri, ByVal from As String, ByVal [to] As String, ByVal messageId As String)
- Me.uri = uri
- Me.from = from
- Me.to = [to]
- Me.messageId = messageId
- End Sub
- Sub send()
- Threading.ThreadPool.QueueUserWorkItem(AddressOf SendMDN)
- End Sub
- Private Function SendMDN() As HttpResponseMessage
- Threading.Thread.Sleep(10000)
- Using httpClient As New HttpClient
- Using content = New MultipartContent("report")
- 'content.Headers.TryAddWithoutValidation("Content-Type", "report-type=disposition-notification")
- content.Headers.Add("Message-Id", String.Format("<AS2_{0}@{1}>", Date.Now.ToString("yyyyMMddHHmmssfff"), "247"))
- content.Headers.Add("AS2-Version", "1.1")
- content.Headers.Add("AS2-From", from)
- content.Headers.Add("AS2-To", [to])
- Dim contentText = "Receipt text"
- content.Add(New StringContent(contentText))
- Dim contentHeaders = "Disposition: automatic-action/MDN-sent-automatically; processed" & vbNewLine &
- "Final-Recipient: rfc822; " & [to] & vbNewLine &
- "Original-Recipient: rfc822; " & [to] & vbNewLine &
- "Original-Message-ID: " & messageId & vbNewLine
- content.Add(New StringContent(contentHeaders, Encoding.UTF8, "message/disposition-notification"))
- Return httpClient.PostAsync(uri, content).Result
- End Using
- End Using
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement