001.
<%@ Page Language=
"VB"
debug=
"true"
validateRequest=false %>
002.
<%@ Import
Namespace
=
"System.Data"
%>
003.
<%@ Import
Namespace
=
"System.Data.Odbc"
%>
004.
<%@ Import
Namespace
=
"System.Web"
%>
005.
<%@ Import
Namespace
=
"System.Web.Mail"
%>
006.
<%@ Import
Namespace
=
"System.Net.Mail"
%>
007.
008.
<script language=
"VB"
runat=
"server"
>
009.
010.
Sub
Page_Load(sender
As
Object
, e
As
EventArgs)
011.
012.
End
Sub
013.
014.
Sub
SendLocal(sender
As
Object
, e
As
EventArgs)
015.
System.Threading.Thread.Sleep(1500) //Protect abuse/Spammer
016.
if txtFrom.Text.Length > 0 andalso txtTo.Text.Length > 0 andalso txtSubject.Text.Length > 0 then
017.
018.
try
019.
020.
021.
Dim
mail2 as
New
System.Net.Mail.MailMessage(txtFrom.Text, txtTo.Text, txtSubject.Text, txtBody.Text)
022.
023.
024.
Dim
smtp as new SmtpClient(
"localhost"
)
025.
026.
smtp.Send(mail2)
027.
028.
029.
catch ex as Exception
030.
031.
response.write (ex.Message)
032.
033.
End
Try
034.
035.
end if
036.
End
Sub
037.
038.
Sub
SendAuthen(sender
As
Object
, e
As
EventArgs)
039.
if txtFrom.Text.Length > 0 andalso txtTo.Text.Length > 0 andalso txtSubject.Text.Length > 0 then
040.
System.Threading.Thread.Sleep(1500) //Protect abuse/Spammer
041.
042.
043.
044.
SendEMail(txtFrom.Text,txtTo.Text,txtSubject.Text,txtBody.Text,
"203.151.233.62"
,
"test123@micthailand.net"
,
"ln$#g19ss19"
,
True
)
045.
046.
txtFrom.Text =
""
047.
txtTo.Text =
""
048.
txtSubject.Text =
""
049.
050.
end if
051.
End
Sub
052.
053.
054.
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
)
055.
Dim
m
As
New
Mail.MailMessage
056.
057.
m.From = SenderAddress
058.
m.
To
= ReceiverAddress
059.
m.Subject = subject
060.
m.Body = Message
061.
062.
063.
If
IsHTMLFormat
Then
064.
m.BodyFormat = MailFormat.Html
065.
Else
066.
m.BodyFormat = MailFormat.Text
067.
End
If
068.
069.
070.
Try
071.
Mail.SmtpMail.SmtpServer = SMTPserver
072.
073.
If
(UserName.Length > 0
And
Password.Length > 0)
Then
077.
078.
End
If
079.
080.
Mail.SmtpMail.Send(m)
081.
082.
Catch
wx
As
Web.HttpException
083.
response.Write(
"Can't Send mail "
& wx.Message)
084.
Catch
ex
As
Exception
085.
response.Write(
"Can't Send mail "
& ex.Message)
086.
End
Try
087.
End
Function
088.
089.
Public
Function
SendEMail(
ByVal
SenderAddress
As
String
,
ByVal
ReceiverAddress
As
String
,
ByVal
subject
As
String
,
ByVal
Message
As
String
)
090.
Dim
m
As
New
Mail.MailMessage
091.
092.
m.From = SenderAddress
093.
m.
To
= ReceiverAddress
094.
m.Subject = subject
095.
m.Body = Message
096.
097.
098.
Try
099.
100.
Mail.SmtpMail.SmtpServer =
"localhost"
101.
m.BodyEncoding = System.Text.Encoding.UTF8
102.
m.Headers.Add(
"Content-Transfer-Encoding"
,
"quoted-printable"
)
103.
104.
Mail.SmtpMail.Send(m)
105.
106.
Catch
wx
As
Web.HttpException
107.
response.Write(
"Can't Send mail "
& wx.Message)
108.
Catch
ex
As
Exception
109.
response.Write(
"Can't Send mail "
& ex.Message)
110.
End
Try
111.
End
Function
112.
</script>
113.
114.
<html>
115.
<head>
116.
<title>Test query information</title>
117.
</head>
118.
<body>
119.
120.
<form runat=
"server"
id=
121.
From:
122.
<asp:TextBox runat=
"server"
id=
"txtFrom"
style=
" LEFT: 100px; POSITION: absolute; TOP: 20px"
/><br>
123.
To
:
124.
<asp:TextBox runat=
"server"
id=
"txtTo"
style=
" LEFT: 100px; POSITION: absolute; TOP: 45px"
/><br>
125.
Subject:
126.
<asp:TextBox runat=
"server"
id=
"txtsubject"
style=
" LEFT: 100px; POSITION: absolute; TOP: 70px"
/><br>
127.
Body :
128.
<asp:TextBox runat=
"server"
id=
"txtBody"
TextMode=
"MultiLine"
style=
" LEFT: 100px; POSITION: absolute; TOP: 95px"
></asp:TextBox><br>
129.
<asp:Button runat=
"server"
id=
"btnSendLocal"
Text=
"Send Local"
style=
" LEFT: 100px; POSITION: absolute; TOP: 135px"
OnClick=
"SendLocal"
/>
130.
<asp:Button runat=
"server"
id=
"btnSenAuth"
Text=
"Send Auth"
style=
" LEFT: 100px; POSITION: absolute; TOP: 160px"
OnClick=
"SendAuthen"
/>
131.
</form>
132.
133.
</body>
134.
</html>