如何實(shí)現(xiàn)電子郵件的自動(dòng)發(fā)送?
%@import namespace="system.web.uit"%>
dim mail as new mailmessage
' 建立一個(gè)mailmessage對(duì)象.
mail.to=收件人
mail.form=送件人
mail.subject=主題
mail.bodyformat=格式
mail.body=內(nèi)容
smtpmail.send(mail)
具體代碼如下:
%@ Import Namespace="System.Web.Util" %>
html>
head>
title>千花飛舞之電子郵件發(fā)送/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>發(fā)件人:/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>內(nèi)容:/Td>
Td>TextArea id="mailbody" Rows=8 Cols=60 runat="server">
/TextArea>
/Td>/Tr>
/Table>
Input Type="Button" Value="立即發(fā)送" 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對(duì)象的to等屬性.
SmtpMail.Send(mail)
' 調(diào)用smtpmail發(fā)送.
Label1.Text = "恭喜,郵件發(fā)送成功!"
End Sub
/script>
[1]