Send Email
Page
Please complete input form:
<asp:Label ID="Confirm" runat="server" >
<asp:Label ID="litStatus" runat="server" style="color: Gray; padding-left: 20px;">
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID"
DataSourceID="AccessDataSource1" DefaultMode="Insert">
<InsertItemTemplate>
Your Name:<asp:TextBox ID="NameTextBox" runat="server"
Text='< %# Bind("Name") %>' Class="inputText" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ErrorMessage="<font color='red'>*</font>"
ControlToValidate="NameTextBox"></asp:RequiredFieldValidator>
Code Number:<asp:TextBox ID="CodeNumberTextBox" runat="server"
Text='< %# Bind("CodeNumber") %>' Class="inputText" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
runat="server" ErrorMessage="<font color='red'>*</font>"
ControlToValidate="TicketNumberTextBox">
<asp:Button ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Submit" />
</InsertItemTemplate>
</asp:FormView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/MyDB.accdb"
DeleteCommand="DELETE FROM [Table1] WHERE [ID] = ?"
InsertCommand="INSERT INTO [Table1] ([Name], [CodeNumber] VALUES (?, ?)"
SelectCommand="SELECT * FROM [Table1]"
UpdateCommand="UPDATE [Table1] SET [Name] = ?, [CodeNumber] = ?"
OnInserted="InsertMessage" >
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="CodeNumber" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="CodeNumber" Type="Int32" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
</asp:AccessDataSource>
Code behind
Sub InsertMessage(ByVal source As Object, ByVal e As SqlDataSourceStatusEventArgs)
If e.AffectedRows > 0 Then
Confirm.Text = "<b> Input received, thank you!" ' - input confirmation msg
Try
Dim SmtpServer As New SmtpClient
Dim mail As New MailMessage
SmtpServer.Credentials = New Net.NetworkCredential("my_username", "my_password")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.google.com" ' - IP address OK as (x.x.x.x)
mail = New MailMessage()
mail.From = New MailAddress("my_email@MyEmailProvider.com")
mail.To.Add("your_email@YourEmailProvider.com")
mail.Subject = "Website input form"
mail.Body = "<p><h2>Website Input Form" +
"<p>New form input has been submitted. " +
"To see the form input,
<a href=""http://mywebsite.com/form_input/"">click here." +
"<p style=""color: gray""><b>Important Message:
This is automatically generated email.
Do not reply to this email."
mail.IsBodyHtml = True ' - type "False" to send email as text;
SmtpServer.Send(mail)
litStatus.Text = "Email has been sent." ' - email sent confirmation
Catch ex As Exception
litStatus.Text = ex.ToString() ' - email error message
End Try
Else
Confirm.Text = "<font color='red'>Not completed - please try again!"
End If
End Sub