<%@import namespace="system.web.uit"%>
dim mail as new mailmessage
' 建立一個mailmessage對象.
mail.to=收件人
mail.form=送件人
mail.subject=主題
mail.bodyformat=格式
mail.body=內容
smtpmail.send(mail)
具體代碼如下:
<%@ Import Namespace="System.Web.Util" %>
<html>
<head>
<title>千花飛舞之電子郵件發送</title>
</head>
<body BgColor="White">
<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>
<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
' 讀取表單的mailto等,分別指定給mail對象的to等屬性.
SmtpMail.Send(mail)
' 調用smtpmail發送.
Label1.Text = "恭喜,郵件發送成功!"
End Sub
</script>
[1]