|
-
March 10th, 2012, 02:06 AM
#6
Re: automatically send an email to the email address in the body of an Outlook email
This works on my site (using Net 2.0) and ASP.Net
Code:
Imports System.Net.Mail
Imports System.String
Imports System
Imports System.Net
Imports System.IO
Imports System.Text
Imports Microsoft.VisualBasic
Partial Class contact
Inherits System.Web.UI.Page
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Try
If Request.UrlReferrer.Host <> Request.Url.Host Then
Return
End If
Dim msg As New MailMessage
msg.To.Add(ConfigurationManager.AppSettings("MailingListEmailTo").ToString)
msg.From = New MailAddress(ConfigurationManager.AppSettings("SiteEmail").ToString)
msg.Subject = "A contact form has been submitted"
msg.IsBodyHtml = True
Dim out As String = ""
If Len(txtAdditional.Text) > 300 Then
out = Left(txtAdditional.Text, 300)
Else
out = txtAdditional.Text
End If
msg.Body = "A new contact form was filled out on the website.<br><br>" & _
Now.ToString & "<br><br>" & _
"Name: " & txtName.Text & "<br>" & _
"Company: " & txtCompany.Text & "<br>" & _
"Email: " & txtEmail.Text & "<br>" & _
"Address: " & txtAddress.Text & "<br>" & _
"Phone: " & txtPhone.Text & "<br>" & _
"Preferred contact method: " & ddlContactMethod.SelectedItem.ToString & "<br>" & _
"Primary business: " & txtBusiness.Text & "<br>" & _
"Time frame: " & txtTimeframe.Text & "<br>" & _
"Heard about from: " & ddlHearAbout.SelectedItem.ToString & "<br>" & _
"Additional: " & out
Dim smtpClient As New SmtpClient
smtpClient.Host = ConfigurationManager.AppSettings("SMTPServer")
smtpClient.Send(msg)
Response.Redirect("default.aspx")
Catch ex As Exception
End Try
End Sub
End Class
Click the button, and I get an email (from my site!)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|