Imports System.Data.SqlClient Imports System.IO Imports System.Net.Mail Partial Class contactus Inherits System.Web.UI.Page ' ASP.NET 3.5 page: contactus ' Developed with: Microsoft Visual Studio 2008 ' Description: Contact details ' Author: Steve Brailey, Cockermouth Mountain Rescue Team, steve@cockermouthmrt.org.uk ' Version 1.05 ' Created: 01/11/08 ' Last updated by: Steve Brailey ' Last updated: 19/01/09 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' Add page metadata and Google search keywords Header.Title = ConfigurationManager.AppSettings("teamabbreviation") & " - Contact us" Dim metaTagDescription As New HtmlMeta metaTagDescription.Name = "Description" metaTagDescription.Content = ConfigurationManager.AppSettings("teamname") & " - Contact us" Header.Controls.Add(metaTagDescription) Dim metaTagKeywords As New HtmlMeta metaTagKeywords.Name = "Keywords" Dim Keywords As String Keywords = "contact us,email,form," & ConfigurationManager.AppSettings("metadatakeywords") metaTagKeywords.Content = Keywords Header.Controls.Add(metaTagKeywords) Dim mpKeywordsLiteral As Literal mpKeywordsLiteral = CType(Master.FindControl("litGoogleKeywords"), Literal) mpKeywordsLiteral.Text = Keywords Dim metaTagAuthor As New HtmlMeta metaTagAuthor.Name = "Author" metaTagAuthor.Content = ConfigurationManager.AppSettings("metadataauthor") Header.Controls.Add(metaTagAuthor) txtForename.Focus() End Sub Protected Sub butSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles butSubmit.Click Dim ErrorText As String Try If Not Page.IsValid Then Exit Sub End If Dim Fullname As String Fullname = txtForename.Text & " " & txtSurname.Text 'If chkSave.Checked Then ' ' Insert contact details into database ' Dim ContactConnectionString As String ' ContactConnectionString = ConfigurationManager.ConnectionStrings("LDSAMRASqlConnection").ConnectionString ' Dim cnContact As SqlConnection ' cnContact = New SqlConnection(ContactConnectionString) ' Try ' cnContact.Open() ' Dim cmdLink As New SqlCommand ' cmdLink.CommandType = Data.CommandType.StoredProcedure ' cmdLink.CommandText = "contactinsert" ' cmdLink.Connection = cnContact ' cmdLink.CommandType = Data.CommandType.StoredProcedure ' Dim PostedByParam As New SqlParameter("forename", Data.SqlDbType.VarChar, 50) ' PostedByParam.Value = txtForename.Text ' cmdLink.Parameters.Add(PostedByParam) ' Dim PostedDateParam As New SqlParameter("surname", Data.SqlDbType.VarChar, 50) ' PostedDateParam.Value = txtSurname.Text ' cmdLink.Parameters.Add(PostedDateParam) ' Dim TitleParam As New SqlParameter("emailaddress", Data.SqlDbType.VarChar, 255) ' TitleParam.Value = txtEmailAddress.Text ' cmdLink.Parameters.Add(TitleParam) ' cmdLink.ExecuteNonQuery() ' cmdLink = Nothing ' Dim LogEntry1 As New Log(Server.MapPath(""), Path.GetFileName(HttpContext.Current.Request.FilePath).ToLower, 0, "Contact " & Fullname & " added to database", True, True) ' LogEntry1.Write() ' LogEntry1 = Nothing ' Catch ex As Exception ' ErrorText = ex.Message ' Dim LogEntry1 As New Log(Server.MapPath(""), Path.GetFileName(HttpContext.Current.Request.FilePath).ToLower, 0, "Add contact " & Fullname & " to database. Error: " & ErrorText, True, True) ' LogEntry1.Write() ' LogEntry1 = Nothing ' Finally ' cnContact.Dispose() ' End Try 'End If ' Build email message Dim EmailBody As String, EmailSubject As String EmailBody = Fullname & " has contacted LDSAMRA using the website contact form." EmailBody = EmailBody & "The message is:" & vbCrLf & vbCrLf EmailBody = EmailBody & txtMessage.Text.Trim & vbCrLf & vbCrLf EmailBody = EmailBody & "Their email address is:" & txtEmailAddress.Text & vbCrLf & vbCrLf EmailSubject = Fullname & " has contacted LDSAMRA using the website contact form" ' Send email message Dim Email As New System.Net.Mail.MailMessage("secretary@ldsamra.org.uk", ConfigurationManager.AppSettings("emailcontactaddress")) Email.Subject = EmailSubject Email.Body = EmailBody Dim mailClient As New System.Net.Mail.SmtpClient() Dim basicAuthenticationInfo As New System.Net.NetworkCredential("secretary@ldsamra.org.uk", "Yhst30_0") mailClient.Host = "smtp.office365.com" mailClient.UseDefaultCredentials = False mailClient.Credentials = basicAuthenticationInfo mailClient.Send(Email) mailClient = Nothing 'Dim MailObject As Object 'MailObject = Server.CreateObject("Persits.MailSender") 'MailObject.From = txtEmailAddress.Text 'MailObject.FromName = Fullname 'MailObject.AddAddress(ConfigurationManager.AppSettings("emailcontactaddress")) 'MailObject.Username = ConfigurationManager.AppSettings("emailusername") 'MailObject.Password = ConfigurationManager.AppSettings("emailpassword") 'MailObject.Subject = EmailSubject 'MailObject.Body = EmailBody 'MailObject.Host = ConfigurationManager.AppSettings("emailhost") 'MailObject.Send() 'MailObject = Nothing Dim LogEntry2 As New Log(Server.MapPath(""), Path.GetFileName(HttpContext.Current.Request.FilePath).ToLower, 0, "Contact form email sent from " & Fullname & " at " & txtEmailAddress.Text & " to " & ConfigurationManager.AppSettings("emailcontactaddress"), True, True) LogEntry2.Write() LogEntry2 = Nothing Response.Redirect("publicresult.aspx?message=Your message has been successfully sent to LDSAMRA", False) ' Old code 'Dim MailObject As Object 'MailObject = Server.CreateObject("Persits.MailSender") 'EmailSubject = txtName.Text & " has contacted LDSAMRA using the website contact form" 'Dim Email1 As New emailsend(MailObject, ConfigurationManager.AppSettings("emailusername"), ConfigurationManager.AppSettings("emailpassword"), ConfigurationManager.AppSettings("emailhost"), EmailSubject, EmailBody, ConfigurationManager.AppSettings("emailaddressfrom"), ConfigurationManager.AppSettings("emailaddressfromname"), ConfigurationManager.AppSettings("emilacontactaddress"), "", ConfigurationManager.AppSettings("emailacontactname")) 'Email1.Send() 'If Email1.GetError = "" Then 'Response.Redirect("publicresult.aspx?message=Your message has been successfully sent to LDSAMRA", False) 'Else 'Response.Redirect("publicresult.aspx?message=Due to technical problems it has not been possible to send your message. It would help us to identify the problem if you could email us the error message to " & ConfigurationManager.AppSettings("emailcontactaddress") & ": " & Email1.GetError, False) 'End If 'Email1 = Nothing Catch ex As Exception ErrorText = ex.Message Dim LogEntry As New Log(Server.MapPath(""), Path.GetFileName(HttpContext.Current.Request.FilePath).ToLower, 0, "Email send. Error: " & ErrorText, True, True) LogEntry.Write() LogEntry = Nothing Response.Redirect("publicresult.aspx?message=Due to technical problems it has not been possible to send your message. It would help us to identify the problem if you could email us the error message to " & ConfigurationManager.AppSettings("emailcontactaddress") & ": " & ex.Message, False) End Try End Sub Sub DateCheck(ByVal sender As Object, ByVal args As ServerValidateEventArgs) Dim DateSpamCheck As New datevalidation(txtDate.Text) args.IsValid = DateSpamCheck.CheckDays(1) End Sub End Class