将Web响应作为邮件发送 [英] Sending Web Response as Mail
本文介绍了将Web响应作为邮件发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在关注以下异常.
无法连接到远程服务器.
有人可以建议我吗?
Hi,
I am getting following exception.
Unable to connect to the remote server.
Could any one suggest me ?
Private Sub cmdSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSend.Click
Dim intLoop As Integer
Dim strSQL, strEmail, strUrl, strMessage, strHtml As String
Dim strWebUrl As String
Dim objDS As DataSet
strUrl = ""
Try
'---------------------------------
' Sending the DueList to admin
'---------------------------------
strSQL = "Select email from t_Users where userlevel=0 and InstituteId=" & Val(Trim$("" & Session("InstId")))
objDS = SQLGet(strSQL, "t_users")
With objDS.Tables("t_users")
If .Rows.Count Then
For intLoop = 0 To .Rows.Count - 1
mstrClass = Trim$("" & cmbClass.SelectedValue)
mstrSec = Trim$("" & cmbSec.SelectedValue)
strEmail = Trim$("" & .Rows(intLoop).Item(0))
strWebUrl = mstrWebURL & "Reports/rptSyllabusStatus.aspx?View=True" & "&C=" & mstrClass & "&S=" & mstrSec
strMessage = "<a href=" & strUrl & ">Click here to view the Fee Duelist</a>"
strHtml = Trim$("" & GetBodyText(strWebUrl))
strMessage = Trim$("" & GetReportMessage(Val(Trim$("" & Session("InstId"))), "SyllabusStatus"))
If Len(strMessage) = 0 Then
strMessage = "Please view the Class Syllabus Status given below."
End If
strMessage = "To,<br>Respected Sir/Madam,<br>" & strMessage & "<br></br></br></br>" & strHtml
SendEmail(Val(Trim$("" & Session("InstId"))), strEmail, "Syllabus Status", strMessage)
'If gblnSend = False Then
' ShowMessage("Please enter the valid Settings in the email settings screen", Page)
' Exit Sub
'End If
ShowMessage("Mail has been sent to Administrator", Page)
Next
End If
End With
Catch ex As Exception
SendErrorReport(Val(Trim$("" & Session("InstId"))), "frmSyllabusRep_Send", ex.Message)
End Try
End Sub
Public Function GetBodyText(ByVal astrUrl As String)
Try
Dim uri As New Uri(astrUrl)
If (uri.Scheme = uri.UriSchemeHttp) Then
Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
request.Method = WebRequestMethods.Http.Get
request.ContentType = "application/x-www-form-urlencoded"
Dim oResponse As HttpWebResponse = request.GetResponse()
Dim reader As New StreamReader(oResponse.GetResponseStream())
Dim tmp As String = reader.ReadToEnd()
GetBodyText = tmp
oResponse.Close()
End If
Catch ex As Exception
SendErrorReport(Val(gtxtInstId.Text), "Global-GetBodyText", ex.Message)
End Try
'Dim sHTMLResult As String = ""
'Try
' Dim HttpWReq As HttpWebRequest = WebRequest.Create(astrUrl)
' HttpWReq.KeepAlive = False
' Dim HttpWResp As HttpWebResponse = HttpWReq.GetResponse()
' sHTMLResult = New StreamReader(HttpWResp.GetResponseStream(), ASCII).ReadToEnd()
' GetBodyText = sHTMLResult
'Catch ex As Exception
' SendErrorReport(Val(gtxtInstId.Text), "Global-GetBodyText", ex.Message)
'End Try
End Function
推荐答案
(" 和会话(" InstId"))) objDS = SQLGet(strSQL," ) 使用 objDS.Tables(" ) 如果 .rows.Count 然后 For intLoop = 0 收件人.计数- 1 mstrClass =修剪
("" & Session("InstId"))) objDS = SQLGet(strSQL, "t_users") With objDS.Tables("t_users") If .Rows.Count Then For intLoop = 0 To .Rows.Count - 1 mstrClass = Trim
(" & cmbClass.SelectedValue ) mstrSec =修剪
("" & cmbClass.SelectedValue) mstrSec = Trim
(" & cmbSec.SelectedValue ) strEmail =修剪
("" & cmbSec.SelectedValue) strEmail = Trim
这篇关于将Web响应作为邮件发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文