Я отправляю электронное письмо с помощью mailgun. Тело электронной почты - это html-контент, у которого есть URL-адрес с параметрами строки запроса. В полученном письме содержимое разбилось на символ «&» в строке запроса. Я использую vb.net со стандартным httpwebrequest.mailgun разрывает электронную почту в амперсанде в строке запроса (тело электронной почты)
Цените любую помощь здесь.
Вот пример кода:
Try
Body = "<br/>Please take a moment to review and sign your payment.</p><p><a href='http://test.com/signme.aspx?ID=xxxxxxxx&ID2=xxxxxx=='> Click here to review and electronically sign the authorization</a></p>"
Dim strDataToPost As String = String.Empty
Dim myWebRequest As HttpWebRequest
Dim myRequestStream As Stream
Dim myStreamWriter As StreamWriter
Dim myWebResponse As HttpWebResponse
Dim myResponseStream As Stream
Dim myStreamReader As StreamReader
myWebRequest = WebRequest.Create(URL)
' Set the method to "POST" and the content type so the server knows to expect form data in the body of the request.
With myWebRequest
.Method = "POST"
.ContentType = "application/x-www-form-urlencoded"
End With
myWebRequest.Credentials = New NetworkCredential("api", "mykey")
strDataToPost = strDataToPost + "from=" + FromEmail
strDataToPost = strDataToPost + "&to=" + ToEmail
If Cc.Trim.Length > 0 Then strDataToPost = strDataToPost + "&cc=" + Cc
If Bcc.Trim.Length > 0 Then strDataToPost = strDataToPost + "&bcc=" + Bcc
strDataToPost = strDataToPost + "&subject=" + Subject
strDataToPost = strDataToPost + "&html=" + HttpUtility.HtmlDecode(Body)
' Get a handle on the Stream of data we're sending to the remote server, connect a StreamWriter to it,
' and write our data to the Stream using the StreamWriter.
myRequestStream = myWebRequest.GetRequestStream()
myStreamWriter = New StreamWriter(myRequestStream)
myStreamWriter.Write(strDataToPost)
'WriteToLogFile("Data :" & strDataToPost)
myStreamWriter.Flush()
myStreamWriter.Close()
myRequestStream.Close()
' Get the response from the remote server.
myWebResponse = myWebRequest.GetResponse()
' Get the server's response status?
' Just like when we sent the data, we'll get a reference to the response Stream, connect a StreamReader to the Stream and
' use the reader to actually read the reply.
myResponseStream = myWebResponse.GetResponseStream()
myStreamReader = New StreamReader(myResponseStream)
Dim strResult As String = myStreamReader.ReadLine()
myStreamReader.Close()
myResponseStream.Close()
myWebResponse.Close()
Catch ex As Exception
WriteToLogFile("Error Occured:" & ex.Message)
End Try
привет soohoonigan, спасибо за ответ. Я пробовал HTMLEncode, mailgun возвращался с ошибкой (неверный запрос). – user6780213