快速业务通道

ASP.NET实现发送Email完整实例

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-04-12
Optional: Set the priority of the message to high
mailObj.Priority = MailPriority.High
'' Optional: Attach a file to the email.
'' Note here that we have created a MailAttachment object to
'' attach a file to the email
mailObj.Attachments.Add(new MailAttachment("c:\test.doc"))
'' Send the email using the SmtpMail object
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〉

在以上例子中,From(发件人)和 To(收件人)的Email地址是从相应的文本框中收集的,点击“Send Mail”(发送邮件)按钮时,邮件就被发送出去。当“Send Mail”(发送邮件)按钮被点击时,表单回递到它自己,在服务器上“SendMail”(发送邮件)程序被触发,邮件被发送。下面是使用C#的例子:

〈%@page language="C#" %〉
〈%@Import Namespace="System.Web.Util" %〉
〈HTML〉〈BODY〉
〈SCRIPT LANGUAGE="C#" RUNAT="server"〉
// This method is called on the server when the submit
// button is clicked on the client and when the page
// posts back to itself
public void SendMail (Object Obj, EventArgs E)
{
// Instantiate a MailMessage object. This serves as a message object
// on which we can set properties.
MailMessage mailObj = new MailMessage();
// Set the from and to address on the email
mailObj.From = Request.Form("From");
mailObj.To = Request.Form("To");
mailObj.Subject = "Subject Of the Mail";
mailObj.Body = "Body of the Mail";
// Optional: HTML format for the email
mailObj.BodyFormat = MailFormat.Html;
// Optional: Encoding for the message
mailObj.BodyEncoding = MailFormat.Base64;
// Optional: Set the priority of the message to high
mailObj.Priority = MailPriority.High;
// Optional: Attach a file to the email.
// Note here that we have created a MailAttachment object to
// attach a file to the email
mailObj.Attachments.Add(new MailAttachment("c:\\test.doc"));
// Send the email using the SmtpMail object
SmtpMail.Send(mailObj);
}
〈/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〉

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号