Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Drawing
Imports System.IO
Imports System.Net
Imports System.Web
Imports System.Net.Mail
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Text
Public Class EmailSubscribers : Inherits System.Web.UI.Page
Protected RtnHomeButton As System.Web.UI.WebControls.HyperLink
Protected MyDataGrid As System.Web.UI.WebControls.DataGrid
'*******************************************************
'
' The Page_Load event handler on this User Control is used to
' obtain a DataReader of contact information from the Contacts
' table, and then databind the results to a DataGrid
' server control. It uses the ASPNetPortal.ContactsDB()
' data component to encapsulate all data functionality.
'
'*******************************************************
Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not IsPostBack Then
Dim myConnection As New SqlConnection("ASPNETDBConnectionString")
Dim myCommand As New SqlCommand("SELECT emailID email FROM subscriptions", myConnection)
myConnection.Open()
Dim dr As SqlDataReader = myCommand.ExecuteReader()
MyDataGrid.DataSource = dr
MyDataGrid.DataBind()
myConnection.Close()
End If
End Sub
Private Sub GetSelections_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim rowCount As Integer = 0
Dim gridSelections As New StringBuilder()
'Loop through each DataGridItem, and determine which CheckBox controls
'have been selected.
For Each DemoGridItem As DataGridItem In MyDataGrid.Items
'(TextBox)(e.Item.Cells[1].FindControl("edit_Address1"));
Dim myCheckbox As CheckBox = DirectCast(DemoGridItem.Cells(0).FindControl("myCheckbox"), CheckBox)
If myCheckbox.Checked = True Then
rowCount += 1
gridSelections.AppendFormat("The checkbox for {0} was selected<br>", MyDataGrid.DataKeys(DemoGridItem.ItemIndex).ToString())
'Trace.Write("test:2" + MyDataGrid.DataKeys[DemoGridItem.ItemIndex].ToString());
Dim myConnection1 As New SqlConnection("ASPNETDBConnectionString")
Dim myCommand As New SqlCommand("select Email from Pilots Where PilotsID = '" + MyDataGrid.DataKeys(DemoGridItem.ItemIndex).ToString() + "'", myConnection1)
myConnection1.Open()
Dim drn As SqlDataReader = myCommand.ExecuteReader()
drn.Read()
Dim ToEmail As String = DirectCast(drn("Email"), [String])
If ToEmail <> "" Then
Dim Email As New System.Net.Mail.MailMessage(ToEmail)
Email.Subject = "Used Vocational Trucks.com - Sale Notices"
Email.Body = "To Contact Us:<br>Used Vocational Trucks.com<br>PO Box 503145<br>White City, OR 97503 USA<br>541-690-4735<br>[email protected]<br>www.usedvocationaltrucks.com"
Dim mailClient As New System.Net.Mail.SmtpClient()
'This object stores the authentication values
Dim basicAuthenticationInfo As New System.Net.NetworkCredential("[email protected]", "xxxxxNeedDave's email Paswd")
'Put your own, or your ISPs, mail server name onthis next line
mailClient.Host = "[email protected]"
mailClient.UseDefaultCredentials = False
mailClient.Credentials = basicAuthenticationInfo
mailClient.Send(Email)
End If
myConnection1.Close()
End If
Next
Response.Redirect(Request.ApplicationPath)
End Sub
End Class
--------------
<%@ Page language="VB" Debug="true" Inherits="EmailSubscribers" CodeBehind="EmailSubscribers.aspx.vb" AutoEventWireup="false" validateRequest="false" %>
<html>
<head>
<title>
<p>E-Mail Subscribers Posted Sales</p>
</title>
</head>
<body>
<table border="0" cellspacing="0" cellpadding="0" width="600">
<tr>
<td align="left"><b>Send Email to Subscribers</b>(check send mail box)</td>
<td align="right"><asp:hyperlink id="RtnHomeButton" cssclass="printbutton" NavigateUrl="~/Annonymous/index.aspx"
runat="server">Home</asp:hyperlink></td>
</tr>
</table>
<form id="default" method="post" runat="server">
<P><asp:button id="GetSelections" runat="server" Text="Send Email to Subscribers"></asp:button></P>
<P><asp:label id="ResultsInfo" runat="server"></asp:label></P>
<asp:datagrid id="MyDataGrid" runat="server" DataKeyField="Email">
<Columns>
<asp:TemplateColumn HeaderText="Selected">
<ItemTemplate>
<asp:CheckBox ID="myCheckbox" Checked="True" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid></form>
</body>
</html>
|