I've managed to successfully send an email with a CV/Resume attachment attached to it, however how do I add other fields (Full name and Comments) within the form to be displayed in the email.
I have the following code in my 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
And my 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>
In that case you can do like this,
myMailMessage.Body = txtName.Text+",\n"+txtComments.Text;