EmailAttachment(ASP.NET) Đây là một đoạn code nhỏ giúp bạn gửi mail có kèm (attach) tập tin. Hy vọng đoạn code giúp ích cho các bạn trong công việc. <%@ Page Language=''VB'' ClientTarget=''downlevel'' %> <%@ Import Namespace=''System.Web.Mail'' %> <script language=''VB'' runat=''server''> Sub btnSendMail_OnClick(Source As Object, E As EventArgs) Dim myMessage As New MailMessage Dim myAttachment As MailAttachment Dim myMail As SmtpMail Dim strEmail As String If Page.IsValid() Then strEmail = txtEmail.Text myMessage.From = ''webmaster@'' & Request.ServerVariables(''SERVER_NAME'') myMessage.To = strEmail myMessage.Subject = ''E-mail Sample from VASC!'' myMessage.Body = ''This message was sent from sample code '' myAttachment = New MailAttachment(Server.MapPath(''attachment.txt'')) ' tập tin bạn chọn myMessage.Attachments.Add(myAttachment) myMail.SmtpServer = ''localhost'' ' hoặc SMTP Server nào bạn định myMail.Send(myMessage) frmEmail.Visible = False lblUserMessage.Text = ''Your message (with attachment) has been sent to '' & strEmail & ''.'' End If End Sub </script> <html> <head> <title>ASP.NET Email (with Attachment) Sample</title> </head> <body> <asp:Label id=''lblUserMessage'' text=''Enter your e-mail address:'' runat=''server'' /> <form method=''post'' id=''frmEmail'' runat=''server''> <asp:TextBox id=''txtEmail'' size=''30'' runat=''server'' /> <asp:RequiredFieldValidator runat=''server'' id=''validEmailRequired'' ControlToValidate=''txtEmail'' errormessage=''Please enter an email address.'' display=''Dynamic'' /> <asp:RegularExpressionValidator runat=''server'' id=''validEmailRegExp'' ControlToValidate=''txtEmail'' ValidationExpression=''^[\w-]+@[\w-]+\.(com|net|org|edu|mil)$'' errormessage=''Please enter a valid email address.'' Display=''Dynamic'' /> <asp:Button id=''btnSendMail'' text=''Send Mail!'' OnClick=''btnSendMail_OnClick'' runat=''server'' /> </form> </body> </html> . New MailMessage Dim myAttachment As MailAttachment Dim myMail As SmtpMail Dim strEmail As String If Page.IsValid() Then strEmail = txtEmail.Text myMessage.From. '' myAttachment = New MailAttachment(Server.MapPath('&apos ;attachment. txt'')) ' tập tin bạn chọn myMessage.Attachments.Add(myAttachment)