嘿,所以我正在处理一个小小的电子邮件表格,这是我到目前为止所做的:
Name:
<br />
<asp:TextBox ID="txtname" runat="server" class="txt" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtfname" />
<br />
<br />
E-mail:
<br />
<asp:TextBox ID="txtemail" runat="server" class="txt" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ValidationExpression="\w+@\w+\.\w+" ControlToValidate="txtemail" />
<br />
<br />
Message:
<br />
<asp:TextBox ID="txtmsg" runat="server" class="txt1" TextMode="MultiLine" Width="300"
Height="100" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtmsg" />
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Send2Mail" />
<asp:Button ID="Button2" runat="server" Text="Reset" />
我现在需要将我的上一个文本框内容发送到我的电子邮箱:
<asp:TextBox ID="txtmsg" runat="server" class="txt1" TextMode="MultiLine" Width="300"
我一直在环顾四周,似乎与Mail属性有些混淆,不同版本的VB.NET无法正常工作......
我正在使用3.5版本,我在我的代码背后尝试了类似的东西:
Dim objMail As New System.Net.Mail()
objMail.To = "TAREGET_EMAIL@ADRESS"
objMail.From = txtemail.Text
objMail.Subject = "Contact form - Joao"
objMail.Body = "Name : " + txtname.Text + vbNewLine + "Email : " + txtemail.text + vbNewLine + "Message : " + txtmsg.text
这不起作用,最大的问题似乎是声明这个Mail变量......
有关如何将我的内容从txtmsg发送到我的电子邮件的任何提示?
答案 0 :(得分:1)
试试这个
Const ToAddress As String = "you@youremail.com"
Dim mm As New MailMessage(txtemail.Text, ToAddress)
mm.Subject = "Contact form - Joao"
mm.Body ="Name : " + txtname.Text + vbNewLine + "Email : " + txtemail.text + vbNewLine + "Message : " + txtmsg.text
mm.IsBodyHtml = False
Dim smtp As New SmtpClient
smtp.Send(mm)
查看此http://www.4guysfromrolla.com/articles/072606-1.aspx
希望它可以帮到你