Send a simple email message with an attachment using ASP.NET 2.0
Imports System.Net.Mail
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Try
Dim SendFrom As MailAddress = New MailAddress(txtFrom.Text)
Dim SendTo As MailAddress = New MailAddress(txtTo.Text)
Dim MyMessage As MailMessage = New MailMessage(SendFrom, SendTo)
MyMessage.Subject = txtSubject.Text
MyMessage.Body = txtBody.Text
Dim attachFile As New Attachment(txtAttachmentPath.Text)
MyMessage.Attachments.Add(attachFile)
Dim emailClient As New SmtpClient(txtSMTPServer.Text)
emailClient.Send(MyMessage)
litStatus.Text = "Message Sent"
Catch ex As Exception
litStatus.Text = ex.ToString()
End Try
End Sub
End Class
0 comments:
Post a Comment