<%@ Page Language="VB" debug="true" validateRequest=false %>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Data.Odbc" %>
<%@ Import Namespace = "System.Web" %>
<%@ Import Namespace = "System.Web.Mail" %>
<%@ Import Namespace = "System.Net.Mail" %>
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
End Sub
Sub SendLocal(sender As Object, e As EventArgs)
System.Threading.Thread.Sleep(1500) //Protect abuse/Spammer
if txtFrom.Text.Length > 0 andalso txtTo.Text.Length > 0 andalso txtSubject.Text.Length > 0 then
try
Dim mail2 as New System.Net.Mail.MailMessage(txtFrom.Text, txtTo.Text, txtSubject.Text, txtBody.Text)
'Dim mail2 as New MailMessage()
Dim smtp as new SmtpClient("localhost")
smtp.Send(mail2)
catch ex as Exception
response.write (ex.Message)
End Try
end if
End Sub
Sub SendAuthen(sender As Object, e As EventArgs)
if txtFrom.Text.Length > 0 andalso txtTo.Text.Length > 0 andalso txtSubject.Text.Length > 0 then
System.Threading.Thread.Sleep(1500) //Protect abuse/Spammer
'SendEMail(txtFrom.Text,txtTo.Text,txtSubject.Text,txtBody.Text,"localhost","","",True)
SendEMail(txtFrom.Text,txtTo.Text,txtSubject.Text,txtBody.Text,"203.151.233.62","[email protected]","ln$#g19ss19",True)
txtFrom.Text = ""
txtTo.Text = ""
txtSubject.Text = ""
'Response.Write("Send already")
end if
End Sub
Public Function SendEMail(ByVal SenderAddress As String, ByVal ReceiverAddress As String, ByVal subject As String, ByVal Message As String, ByVal SMTPserver As String, ByVal UserName As String, ByVal Password As String, ByVal IsHTMLFormat As Boolean)
Dim m As New Mail.MailMessage
m.From = SenderAddress
m.To = ReceiverAddress
m.Subject = subject
m.Body = Message
If IsHTMLFormat Then
m.BodyFormat = MailFormat.Html
Else
m.BodyFormat = MailFormat.Text
End If
Try
Mail.SmtpMail.SmtpServer = SMTPserver
If (UserName.Length > 0 And Password.Length > 0) Then
m.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
m.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = UserName
m.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = Password
End If
Mail.SmtpMail.Send(m)
Catch wx As Web.HttpException
response.Write("Can't Send mail " & wx.Message)
Catch ex As Exception
response.Write("Can't Send mail " & ex.Message)
End Try
End Function
Public Function SendEMail(ByVal SenderAddress As String, ByVal ReceiverAddress As String, ByVal subject As String, ByVal Message As String)
Dim m As New Mail.MailMessage
m.From = SenderAddress
m.To = ReceiverAddress
m.Subject = subject
m.Body = Message
Try
Mail.SmtpMail.SmtpServer = "localhost"
m.BodyEncoding = System.Text.Encoding.UTF8
m.Headers.Add("Content-Transfer-Encoding", "quoted-printable")
Mail.SmtpMail.Send(m)
Catch wx As Web.HttpException
response.Write("Can't Send mail " & wx.Message)
Catch ex As Exception
response.Write("Can't Send mail " & ex.Message)
End Try
End Function
</script>
<html>
<head>
<title>Test query information</title>
</head>
<body>
<form runat="server" id='SendMail' >
From:
<asp:TextBox runat="server" id="txtFrom" style=" LEFT: 100px; POSITION: absolute; TOP: 20px" /><br>
To:
<asp:TextBox runat="server" id="txtTo" style=" LEFT: 100px; POSITION: absolute; TOP: 45px"/><br>
Subject:
<asp:TextBox runat="server" id="txtsubject" style=" LEFT: 100px; POSITION: absolute; TOP: 70px"/><br>
Body :
<asp:TextBox runat="server" id="txtBody" TextMode="MultiLine" style=" LEFT: 100px; POSITION: absolute; TOP: 95px"></asp:TextBox><br>
<asp:Button runat="server" id="btnSendLocal" Text="Send Local" style=" LEFT: 100px; POSITION: absolute; TOP: 135px" OnClick="SendLocal"/>
<asp:Button runat="server" id="btnSenAuth" Text="Send Auth" style=" LEFT: 100px; POSITION: absolute; TOP: 160px" OnClick="SendAuthen"/>
</form>
</body>
</html>