Imports System.Web.Mail
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents Button2 As System.Web.UI.WebControls.Button
Protected WithEvents ListBox1 As System.Web.UI.WebControls.ListBox
Protected WithEvents ListBox2 As System.Web.UI.WebControls.ListBox
Protected WithEvents ListBox3 As System.Web.UI.WebControls.ListBox
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Public Sub AutoGen(ByRef EmailMessage As String)
Dim RanInteger As Integer
Randomize()
RanInteger = Int((3 - 1 + 1) * Rnd() + 1)
Select Case RanInteger
Case 1
EmailMessage = "Dear Mr. Yehhui," & _
"<br>" & _
"<br> USCNC has cheap and efficient products! Please visit our site!" & _
"<br>" & _
"<br> <a href=""\\server\public\IT Folder\Ian Paul\Ian\a.htm"">[url]http://localhost/autoemail/a.htm[/url] </a> "
Case 2
EmailMessage = "Dear Yehhui," & _
"<br>" & _
"<br> We, at USCNC, have a huge selection of IT products at our disposal." & _
"<br>" & _
"<br> Please click to this link." & _
"<br>" & _
"<br> <a href=""\\server\public\IT Folder\Ian Paul\Ian\a.htm"">[url]http://localhost/autoemail/a.htm[/url] </a> "
Case 3
EmailMessage = "Mr. Yehhui," & _
"<br>" & _
"<br> Want to buy a cool computer but short of cash?" & _
"<br>" & _
"<br> Then we have the solution for you." & _
"<br>" & _
"<br> USCNC have a lot of cool computers at affordable prices." & _
"<br>" & _
"<br> Want to know more?" & _
"<br>" & _
"<br> Please click this link." & _
"<br> <a href=""\\server\public\IT Folder\Ian Paul\Ian\a.htm"">[url]http://localhost/autoemail/a.htm[/url] </a> "
End Select
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim AutoEmail As New MailMessage
Dim EmailMessage As String
Dim ad As ListItem
Dim ae As Integer
Dim x As String
AutoGen(EmailMessage)
ad = ListBox1.Items.Item(ae)
MsgBox(ad)
AutoEmail.To = ListBox1.SelectedValue
AutoEmail.Subject = "Test subject from VB.NET"
AutoEmail.BodyFormat = MailFormat.Html
AutoEmail.Body = EmailMessage
AutoEmail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "25")
System.Threading.Thread.Sleep(200)
SmtpMail.SmtpServer = "192.168.11.11"
System.Threading.Thread.Sleep(200)
SmtpMail.Send(AutoEmail)
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim a As New DataSet
Dim g As New DataSet
Dim h As New DataSet
Dim b As New OleDb.OleDbDataAdapter
Dim d As New OleDb.OleDbDataAdapter
Dim f As New OleDb.OleDbDataAdapter
Dim c As New OleDb.OleDbConnection
c.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\phil\wa.mdb;Persist Security Info=true"
c.Open()
b.SelectCommand = New OleDb.OleDbCommand("SELECT Fname + ' ' + [Emailadd] as expr1 FROM Table1 ;", c)
d.SelectCommand = New OleDb.OleDbCommand("SELECT Fname + ' ' + EmailS as expr2 FROM Table2 ;", c)
f.SelectCommand = New OleDb.OleDbCommand("SELECT Product FROM Table3 ;", c)
b.Fill(a)
d.Fill(g)
f.Fill(h)
ListBox1.DataSource = a
ListBox1.DataTextField = "expr1"
ListBox1.DataValueField = "expr1"
ListBox1.DataBind()
ListBox2.DataSource = g
ListBox2.DataTextField = "expr2"
ListBox2.DataValueField = "expr2"
ListBox2.DataBind()
ListBox3.DataSource = h
ListBox3.DataTextField = "Product"
ListBox3.DataValueField = "Product"
ListBox3.DataBind()
c.Close()
End Sub
End Class