Viewing source for recipe2113vb.aspx

<%@ Import Namespace="System.Web.Mail" %>
<%@ Page Language="VB" %>
<Script Runat="server">

	Public Sub Page_Load(Sender As Object, E As EventArgs)

	  'Clear any previous messages
	  MessageLiteral.Text = ""

	  'Create the MailMessage object and set its properties
	  Dim _Message As New MailMessage()

	  With _Message
		.To = "someone@null.com"
		.From = "someone-else2null.com"
		.Subject = "How to send emails through ASP.NET"
		.Body = "Your Message goes here..." 
	  End With

	  'Make sure to set the path where your file is located...
	  Dim _Attachment As New MailAttachment("c:\myfile.txt")

	  'Add the attachment\s to the _Message object
	  _Message.Attachments.Add(_Attachment)

	  'Specify the name of the SMTP gateway server
	  SmtpMail.SmtpServer="mail.myserver.com"

	  Try
		'Send the email
		 SmtpMail.Send(_Message)
		 MessageLiteral.Text = "Message sent successfully!"

	  Catch Err As Exception
		MessageLiteral.Text = Err.Message

	  End Try

	End Sub

</Script>
<html>
	<head>
		<title>CookBook :: Making attachments with email</title>
	</head>
	<body>
		<form runat="server">
			<asp:Literal id="MessageLiteral" runat="server"></asp:Literal>
		</form>
	</body>
</html>