我有一个表单电子邮件,asp.net 4.0/VB/Visual Studio,我希望它自动进入 Microsoft Access 数据库,而不需要我做任何努力。这可能吗?我不是程序员,但这是电子邮件的形式:
<script runat="server"> Protected Sub SubmitForm_Click(ByVal sender As Object, ByVal e As System.EventArgs) If Not Page.IsValid Then Exit Sub Dim SendResultsTo As String = "me@domain.com" Dim smtpMailServer As String = "smtp.domain.com" Dim smtpUsername As String = "me@domain.com" Dim smtpPassword As String = "******" Dim MailSubject As String = "Form Results" Try Dim txtQ As TextBox = Me.FormContent.FindControl("TextBoxQ") If txtQ IsNot Nothing Then Dim ans As String = ViewState("hf1") If ans.ToLower <> txtQ.Text.ToLower Or ans.ToUpper <> txtQ.Text.ToUpper Then Me.YourForm.ActiveViewIndex = 3 Exit Sub End If End If Dim FromEmail As String = SendResultsTo Dim msgBody As StringBuilder = New StringBuilder() Dim sendCC As Boolean = False For Each c As Control In Me.FormContent.Controls Select Case c.GetType.ToString Case "System.Web.UI.WebControls.TextBox" Dim txt As TextBox = CType(c, TextBox) If txt.ID.ToLower <> "textboxq" Then msgBody.Append(txt.ID & ": " & txt.Text & vbCrLf & vbCrLf) End If If txt.ID.ToLower = "email" Then FromEmail = txt.Text End If If txt.ID.ToLower = "subject" Then MailSubject = txt.Text End If Case "System.Web.UI.WebControls.CheckBox" Dim chk As CheckBox = CType(c, CheckBox) If chk.ID.ToLower = "checkboxcc" Then If chk.Checked Then sendCC = True Else msgBody.Append(chk.ID & ": " & chk.Checked & vbCrLf & vbCrLf) End If Case "System.Web.UI.WebControls.RadioButton" Dim rad As RadioButton = CType(c, RadioButton) msgBody.Append(rad.ID & ": " & rad.Checked & vbCrLf & vbCrLf) Case "System.Web.UI.WebControls.DropDownList" Dim ddl As DropDownList = CType(c, DropDownList) msgBody.Append(ddl.ID & ": " & ddl.SelectedValue & vbCrLf & vbCrLf) End Select Next msgBody.AppendLine() msgBody.Append("Browser: " & Request.UserAgent & vbCrLf & vbCrLf) msgBody.Append("IP Address: " & Request.UserHostAddress & vbCrLf & vbCrLf) msgBody.Append("Server Date & Time: " & DateTime.Now & vbCrLf & vbCrLf) Dim myMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage() myMessage.To.Add(SendResultsTo) myMessage.From = New System.Net.Mail.MailAddress(FromEmail) myMessage.Subject = MailSubject myMessage.Body = msgBody.ToString myMessage.IsBodyHtml = False If sendCC Then myMessage.CC.Add(FromEmail) Dim basicAuthenticationInfo As New System.Net.NetworkCredential(smtpUsername, smtpPassword) Dim MailObj As New System.Net.Mail.SmtpClient(smtpMailServer) MailObj.Credentials = basicAuthenticationInfo MailObj.Send(myMessage) Me.YourForm.ActiveViewIndex = 1 Catch Me.YourForm.ActiveViewIndex = 2 End Try End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) If Not Page.IsPostBack Then Dim lbl As Label = Me.FormContent.FindControl("labelq") If lbl IsNot Nothing Then Dim rq(3) As String rq(0) = "Is fire hot or cold?" rq(1) = "Is ice hot or cold?" rq(2) = "Is water wet or dry?" Dim ra(3) As String ra(0) = "hot" ra(1) = "cold" ra(2) = "wet" Dim rnd As New Random Dim rn As Integer = rnd.Next(0, 3) lbl.Text = rq(rn) ViewState("hf1") = ra(rn) End If End If End Sub </script> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server"> <h1>CONTACT HEALTH
NUTTS AND WORK FROM THE COMFORT OF YOUR OWN HOME!
Enter your Email Address:
* Required * Please enter a valid email address.
Subject:
* Required
Please type your message below: * Required
First Name:
* Required
Last Name:
* Required
Phone Number:
* Required * Please enter a valid U.S. phone number (including dashes).
City:
* Required
State/Province:
* Required
Your message has been sent. Thank you for contacting us.
Due to technical difficulty, your message may NOT have been sent. You did not correctly answer the anti-spam question. Please go back and try again.
当有人填写表格时,我会收到这样一封电子邮件:
Email: rmajeski@yahoo.com
Subject: I need A Job
Message: Me wants job today okay? Thank you for J.O.B
First_Name: Rich
Last_Name: Majeski
Phone: xxx-xxx-xxxx
City: Hockeytown
State: Michigan
Browser: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
IP Address: 108.224.49.14
Server Date & Time: 5/15/2012 6:03:33 AM
如何使它自动进入 Microsoft Access 数据库,而无需我手动执行?任何指导将不胜感激!谢谢!
最佳答案
您可以阅读有关 Office 加载项编程的教程。 一种方法是让此加载项查看 Outlook 中的每一封传入电子邮件,并将字段解析为相应的变量。之后,您可以创建到 MS Access 数据库文件的数据库连接,以使用 SQL-Insert DML 语句插入数据。 我认为这对您来说是最简单的方法,因为编程不会占用太多代码行。但必须运行 MS Outlook!
最好的方法当然是在 ASP.NET 中异步创建数据库连接(使用 ODBC)。网上应该有很多教程。
关于asp.net - 我是否必须手动将来自 asp.net 4 电子邮件的信息输入到 MS 数据库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10605331/