1
我使用mailgun發送電子郵件。電子郵件正文是包含查詢字符串參數的網址的html內容。在收到的電子郵件中,查詢字符串中的內容已打破「&」字符。我用標準httpwebrequest使用vb.net。郵件符號查詢字符串(電子郵件正文)中的郵件符號
欣賞這裏的任何幫助。
下面是示例代碼:
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