如何在我的ASP.NET CV上载表单中添加其他字段

时间:2015-12-07 18:15:28

标签: asp.net vb.net forms email runatserver

我成功发送了附有简历/简历附件的电子邮件,但如何在表单中添加其他字段(全名和评论)以显示在电子邮件中。

我的aspx.vb中有以下代码:

Imports System.Net.Mail
Imports System.IO

Partial Class Default_VB
  Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

    If FileUpload1.HasFile Then

  Dim toAddress As String = "email@address.com"
  Dim fromAddress As String = "email@anotheraddress.com"
  Dim mailServer As String = "smtp.1and1.com"

  Dim myMailMessage As MailMessage = New MailMessage()

  myMailMessage.To.Add(toAddress)
  myMailMessage.From = New MailAddress(fromAddress)
  myMailMessage.Subject = "Test Message"

  Dim fileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
  Dim myAttachment As New Attachment(FileUpload1.FileContent, fileName)
  myMailMessage.Attachments.Add(myAttachment)

  Dim mySmtpClient As New SmtpClient(mailServer)

  mySmtpClient.Send(myMailMessage)

End If

 End Sub
 End Class

我的HTML:

<form id="form1" runat="server">
<div>
<label for="FullName">Full Name:</label> 
<asp:TextBox ID="txtName" runat="server"/> 

<label for="Comments">Comments:</label> 
<asp:TextBox ID="txtComments" runat="server"/>   

<asp:FileUpload ID="FileUpload1" runat="server" />

<asp:Button ID="Button1" runat="server" Text="Send" /></div>

1 个答案:

答案 0 :(得分:0)

在这种情况下你可以这样做,

myMailMessage.Body = txtName.Text+",\n"+txtComments.Text;