如何实现电子邮件的自动发送?
作者:
如何实现电子邮件的自动发送?
<%@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]