Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (44.41 KB, 1 trang )
Email Attachment (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>