.aspx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <%@ Control Language="vb" AutoEventWireup="false" Codebehind="email.ascx.vb" Inherits="DamianM.email" %> <form id="Form1" method="post" runat="server"> <Table id="Table1" width="100%"> <tr runat="server" id="mailRow"> <td width="50%" align="right">Enter Email Address : </td> <td> <asp:TextBox id="Eaddress" runat="server"></asp:TextBox> </td> <td> <asp:Button id="Button1" runat="server" Text="Send Mail"></asp:Button></td> <td width="50%"></td> </tr> </Table> </form> |
Email.aspx.vb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | Imports System.Web Public Class email Inherits System.Web.UI.UserControl Protected WithEvents Button1 As System.Web.UI.WebControls.Button Protected WithEvents Eaddress As System.Web.UI.WebControls.TextBox Protected WithEvents sorryRow As System.Web.UI.HtmlControls.HtmlTableRow Protected WithEvents mailRow As System.Web.UI.HtmlControls.HtmlTableRow Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Page.IsPostBack Then 'mail message objects Dim m As New System.Web.Mail.MailMessage() 'smtp mail object need only defined if you with to Dim s As System.Web.Mail.SmtpMail 'all mail properties are accessable through the mail message objects m.From = "Doable .Net" m.To = Eaddress.Text m.Subject = "Email in .net code sample" m.Body = "Thank you for your interest, see attached code sample." m.Priority = Mail.MailPriority.High 'to make an attachment you need to create a mailattachment object Dim a As New System.Web.Mail.MailAttachment(Server.MapPath("/code/5/email.ascx")) 'attach the atachment to the mail m.Attachments.Add(a) a = New System.Web.Mail.MailAttachment(Server.MapPath("/code/5/email.ascx.vb")) m.Attachments.Add(a) 'designate the smtp server if required 'but here we are using the web servers smtp service ' 's.SmtpServer = "mail.xxxxxxx.com" 'send the mail s.Send(m) End If End Sub End Class |



















