[申明:必须自己试验才能看到效果!:)]
ASP+中、想传送Email,须使用以上两个对象,其中Mailmessage用设定Email的内容、而Smtpmail则是将
Email出去,程序框架如下:
<%@import namespace="system.web.uit"%>
dim mail as new mailmessage '建立一个mailmessage对象
mail.to=收件人
mail.form=送件人
mail.subject=主题
mail.bodyformat=格式
mail.body=内容
smtpmail.send(mail)
由于以上两个对象类别收录于system.web.util namespace,所以<%@import namespace="system.web.uit"%>
标记是必要的。先让我们看一下下面的源程序:
<%@ Import Namespace="System.Web.Util" %>
<HTML>
<Body BgColor="White">
<H2>ASP+ Email发送程序!<Hr></H2>
<Form runat="server">
<Table Border=1>
<Tr><Td>收件人:</Td>
<Td><Input Type="Text" id="mailTo" Size=40 runat="server"/></Td></Tr>
<Tr><Td>发件人:</Td>
<Td><Input Type="Text" id="mailFrom" Size=40 runat="server"/></Td></Tr>
<Tr><Td>主题:</Td>
<Td><Input Type="Text" id="mailSubject" Size=40 runat="server"/></Td></Tr>
<Tr><Td>内容:</Td>
<Td><TextArea id="mailBody" Rows=8 Cols=60 runat="server">
</TextArea>
</Td></Tr>
</Table>
<Input Type="Button" Value="送出" id="Button1"
OnServerClick="Button1_Click" runat="server"/>
</Form>
<Hr>
<ASP:Label id="Label1" runat="server"/>
</Body>
</HTML>
<script Language="VB" runat="server">
Sub Button1_Click(sender As Object, e As EventArgs)
Dim mail As MailMessage = New MailMessage
mail.To= mailTo.Value
mail.From= mailFrom.Value
mail.Subject= mailSubject.Value
mail.BodyFormat=mail.format.text
mail.Body= mailBody.Value
SmtpMail.Send(mail)
Label1.Text = "已成功发送!"
End Sub
</script>
通过读取表单的mailto、mailform、mailsubject、mailbody,然后分别指定给mail对象的to,form,submit,body属性,最后调用smtpmail送出邮件!
呵呵,写东东还真累!!不过也完工了,大家自己试试吧!