Namespace Wings
Public Class MailHandler : Implements IHttpHandler
Public ReadOnly Property IsReusable As Boolean Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property
Sub ProcessRequest(context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim Response As HttpResponse=context.Response
Dim Request As HttpRequest=context.Request
' リクエスト・データを基に、メール本文を組み立てる
Dim objSb As StringBuilder=New StringBuilder
objSb.Append("■■ASP.NET メール送信サービス■■")
objSb.Append(Chr(13) & Chr(10))
objSb.Append("-----------------------------------------")
objSb.Append(Chr(13) & Chr(10))
' フォームから入力されたすべてのキーについて ' 「[キー名] 値」の形式で出力 ' ただし、ビューステートを表すキー“_VIEWSTATE”は除外する
Dim aryKey As String()=Request.Form.AllKeys
For i As Integer=0 To aryKey.GetUpperBound(0)
If aryKey(i)<>"_VIEWSTATE" Then
objSb.Append("[" & aryKey(i) & "] " & _
Request.Form(aryKey(i)) & Chr(13) & Chr(10))
End If
Next
objSb.Append("-----------------------------------------")
objSb.Append(Chr(13) & Chr(10))
objSb.Append(" Presented By ASP.NET1.1")
' 送信メールの情報を設定
' (上から送信元、送り先、件名、本文、本文形式)
Dim objMail As New MailMessage()
objMail.From=Request.Form("_name") & "<" & _
Request.Form("_email") & ">"
objMail.To=Request.Form("_to")
objMail.Subject=Request.Form("_subject")
objMail.Body=objSb.ToString()
objMail.BodyFormat=MailFormat.Text
' 指定されたSMTPサーバを介してメールを送信
SmtpMail.SmtpServer="smtp.xxxxx.ne.jp"
SmtpMail.Send(objMail)
' リンク元のページにリダイレクト
Response.Redirect(Request.UrlReferrer.ToString())
End Sub
End Class
End Namespace