服务器配置在webconfig文件中。
<%@ Page Language="VB" %>
<!DOCTYPE html>
<script runat="server">
Partial Class _Default
Inherits System.Web.UI.Page
'Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Create instance of main mail message class.
Dim mailMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
'Configure mail mesage
'Set the From address with user input
' mailMessage.From = New System.Net.Mail.MailAddress(txtFromAddress.Text.Trim())
'Get From address in web.config
mailMessage.From = New System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings("fromEmailAddress"))
'Another option is the "from" attirbute in the <smtp> element in the web.config.
'Set additinal addresses
'mailMessage.To.Add(New System.Net.Mail.MailAddress(txtToAddress.Text.Trim()))
mailMessage.To.Add(New System.Net.Mail.MailAddress("myemail@web.com"))
'mailMessage.CC
'mailMessage.Bcc
'mailMessage.ReplyTo
'Set additional options
mailMessage.Priority = Net.Mail.MailPriority.High
'Text/HTML
mailMessage.IsBodyHtml = False
'Set the subjet and body text
'mailMessage.Subject = txtSubject.Text.Trim()
mailMessage.Subject = "test email SUBJECT"
'mailMessage.Body = txtBody.Text.Trim()
mailMessage.Body = "body of email test"
'Add one to many attachments
'mailMessage.Attachments.Add(New System.Net.Mail.Attachment("c:\temp.txt")
'Create an instance of the SmtpClient class for sending the email
Dim smtpClient As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
'Use a Try/Catch block to trap sending errors
'Especially useful when looping through multiple sends
Try
smtpClient.Send(mailMessage)
Catch smtpExc As System.Net.Mail.SmtpException
'Log error information on which email failed.
Catch ex As Exception
'Log general errors
End Try
End Sub
End Class
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
•多个收件人 •不知道如何让页面在每次加载页面时发送电子邮件
答案 0 :(得分:1)
页面上有一个page_load方法,就像Windows窗体应用程序中有一个form_load方法一样。从那里运行你的代码?