- 作者:zhaozj
- 发表时间:2020-12-23 10:53
- 来源:未知
步骤2: MailMessage 对象示例声明MailMessage对象。Dim mailObj AS new MailMessage MailMessage 对象属性: 属性 描述 From 发信人的地址To 收信人的地址Subject 邮件主题Body 邮件正文cc 邮件副本接受人地址bcc 邮件副本接受人地址比显示在邮件中(密件)Priority 邮件的优先权BodyEncoding 邮件内码BodyFormat 邮件格式,html或文本Attachments 邮件附件以下的代码片断将展示MailMessage 对象。mailObj.From = "abc@mydomain.com"mailObj.To = Request.Form ("to")mailObj.Subject = "subject of the mail"mailObj.Body = "Message of the mail" 发送邮件使用SmtpMail 对象Send 方法。以下代码片断被使用送邮件SmtpMail.Send(mailObj) vb.net完整源代码<%@page language="VB" %><%@Import Namespace="System.Web.Util" %><HTML><head><title>欢迎使用chenyangasp示例程序</title></head><BODY><SCRIPT LANGUAGE="VB" RUNAT="server">' 这个方法当提交时访问服务器 Sub SendMail (Obj As Object, E As EventArgs)Dim mailObj AS new MailMessage'设置邮件的发送及接收地址mailObj.From = Request.Form("From")mailObj.To = Request.Form("To") mailObj.Subject = "Subject Of the Mail"mailObj.Body = "Body of the Mail" 'html格式的邮件mailObj.BodyFormat = MailFormat.Html '设置为高级优先权mailObj.Priority = MailPriority.High '为邮件添加附件'注意:这里我们创建了一个mailattachment对象添加一个附件到邮件中mailObj.Attachments.Add(new MailAttachment("c:/test.doc"))'使用SmtpMail对象发送邮件SmtpMail.Send(mailObj)End Sub</SCRIPT><asp:label ID="Headingmsg" Text="Enter Your Email Address:" RUNAT="server"/><FORM METHOD="post" RUNAT="server">Email Recipient: <INPUT TYPE="text" NAME="to"> <br>Email Sender: <INPUT TYPE="text" NAME="from"><INPUT TYPE="submit" NAME="Submit" VALUE="Send Mail" RUNAT="server" OnServerClick="SendMail"></FORM></BODY> |