VB.NET – Send Email

Send email using web form – user defines smtp settings.

send-email.aspx
 
To: 
From: 
SMTP Server: 
Subject: 
Attachment: 
Body: 

Action: 

Status: [labelEmailSent]

send-email.aspx.vb

Imports System.Net.Mail

Partial Class Send_Email
    Inherits System.Web.UI.Page
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
                                                              Handles btnSubmit.Click
        Try
            Dim SendFrom As MailAddress = New MailAddress(txtFrom.Text)
            Dim SendTo As MailAddress = New MailAddress(txtTo.Text)

            Dim MyMessage As MailMessage = New MailMessage(SendFrom, SendTo)

            MyMessage.Subject = txtSubject.Text
            MyMessage.Body = txtBody.Text

            Dim attachFile As New Attachment(txtAttachmentPath.Text)
            MyMessage.Attachments.Add(attachFile)

            Dim emailClient As New SmtpClient(txtSMTPServer.Text)
            emailClient.Send(MyMessage)

            litStatus.Text = "Message Sent"
        Catch ex As Exception
            litStatus.Text = ex.ToString()
        End Try
    End Sub
End Class

Increase session timeout

Increase session timeout

web.config

<configuration>
    <system.web>
        <sessionState timeout="240"/>
        <!-- increases session timeout from 20 minutes
             to 240 minutes, or 4 hours
         -->
    </system.web>
</configuration>

However, when increasing the user session timeout keep in mind the following:

"The default is 10 minutes. Session.Timeout has no hard-coded limit. Most
Web administrators set this property to 8 minutes. It should not be set
higher than 20 minutes (except in special cases) because every open session
is holding onto memory. It should also not be set lower than 4 minutes
because clients rarely respond within that time resulting in a loss of session state." Surce Microsoft MSDN

Classic asp delete script


<%
'define variables
DIM objConn, objRS                     'connection
DIM i_last, count, bgcolor             'even row bg color
Dim job, recID                         'fetching query strings         
job = Request.QueryString("do")
recID = Request.QueryString("rid")

Dim sqlstatement                        ' sql query command string


If job = "del" Then
SET objConn = Server.CreateObject("ADODB.Connection")
    objConn.ConnectionTimeOut = 30
    objConn.Open "DSN=MySystemDSN"

          sqlstatement = "DELETE FROM Customers WHERE ID=" &recID
		
	SET objRS = objConn.EXECUTE(sqlstatement)
	objConn.Close
    SET objConn = nothing

End If
%>


'retrieving records
<table>

<%
SET objConn = Server.CreateObject("ADODB.Connection")
    objConn.ConnectionTimeOut = 30
    objConn.Open "DSN=MySystemDSN"
					
    SET objRS = Server.CreateObject("ADODB.RecordSet")
	objRS.Open "SELECT * FROM Tellers ORDER BY Teller_Name",objConn
	 DO WHILE NOT objRS.EOF
	 count=count + 1
	 i_last=right(count,1)
	 select case i_last
	 case "1","3","5","7","9"
	       bgcolor="#DDEAF7"       'odd row bg color
	 case else
               bgcolor="#FFFFFF"       'even row bg color
	 end select
%>
   <tr bgcolor="< %= bgcolor %>">
	<td><%= objRS("Customer_Name") %>
	<td><%= objRS("Customer_Number") %>
	<td>><a href="default.asp?do=del&rid=<%= objRS("ID") %>" 
             onclick="return confirm('Are you sure you want to delete?')" >Delete
   </tr>
<%
        objRS.MoveNext
   LOOP
        objRS.Close
	objConn.Close
					
SET objRS = nothing
SET objConn = nothing
%>
</table>