System.Net.Mail是作为System.Web.Mail的替代来发送EMAIL.
1) System.Net.Mail
<!--<br/ /><br/ />Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ />http://www.CodeHighlighter.com/<br/ /><br/ />-->private void SendMailByNet()
{
MailMessage objMailMessage = new MailMessage();
objMailMessage.From = new MailAddress("UserFromMail");
objMailMessage.To.Add(new MailAddress("UserToMail"));
objMailMessage.BodyEncoding = System.Text.Encoding.UTF8;
objMailMessage.Subject = "This is test";
objMailMessage.Body = "Hi,Pippo<br/><br/> This is testing Email.";
objMailMessage.IsBodyHtml = true;
SmtpClient objSmtpClient = new SmtpClient();
objSmtpClient.Host = "SMTP";
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
objSmtpClient.Credentials = new System.Net.NetworkCredential("UserFromMail", "PWD");
//objSmtpClient.EnableSsl = true;//SMTP 服务器要求安全连接需要设置此属性
try
{
objSmtpClient.Send(objMailMessage);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
2) System.Web.Mail
<!--<br/ /><br/ />Code highlighting produced by Actipro CodeHighlighter (freeware)<br/ />http://www.CodeHighlighter.com/<br/ /><br/ />-->private void SendMailByWeb()
{
MailMessage objMailMessage = new MailMessage();
SmtpMail.SmtpServer = System.Configuration.ConfigurationManager.AppSettings["SMTP"];
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", System.Configuration.ConfigurationManager.AppSettings["FROM"]);
//objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", System.Configuration.ConfigurationManager.AppSettings["PWD"]);//密码可以不提供
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");//SMTP 服务器要求安全连接需要设置此属性
objMailMessage.BodyEncoding = System.Text.Encoding.UTF8;
objMailMessage.From = System.Configuration.ConfigurationManager.AppSettings["FROM"];
objMailMessage.To = "UserToMail";
objMailMessage.Subject = "this is test";
objMailMessage.Body = "Hi Pippo,<br/>This is testing EMAIL.";
objMailMessage.BodyFormat = MailFormat.Html;
try
{
SmtpMail.Send(objMailMessage);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
分享到:
相关推荐
在.NET框架中,`System.Net.Mail`命名空间提供了一组类用于发送电子邮件,这在Windows Forms(WinForms)和Web Forms应用中非常常见。本文将详细介绍如何使用`System.Net.Mail`来实现邮件发送功能,以及在WinForms和...
### ASP.NET 使用 Jmail 和 System.Net.Mail 发送邮件 在 Web 开发中,电子邮件功能是不可或缺的一部分,无论是用于用户注册确认、密码找回还是其他通知用途。ASP.NET 提供了多种方式来实现邮件发送功能,其中两种...
虽然自.NET Framework 4.5起,`System.Web.Mail`已被标记为过时,并推荐使用`System.Net.Mail`命名空间中的`SmtpClient`类来替代,但在早期版本的.NET框架中,`System.Web.Mail`仍然是一个常用的选择。 ### 使用`...
`System.Net.Mail` 命名空间提供了发送电子邮件的功能,其中 `SmtpClient` 类是核心组件,它负责通过SMTP(简单邮件传输协议)发送邮件。`System.Net.Mime` 命名空间则包含了表示MIME(多用途互联网邮件交换)头的类...
在ASP.NET中,发送电子邮件通常使用`System.Net.Mail`命名空间中的类,这是一个非常实用的功能,允许开发者轻松地集成邮件发送功能到他们的应用程序中。 发送邮件的主要涉及以下几个关键步骤和类: 1. **...
### CS.NET中使用System.Web.Mail发送邮件的知识点详解 #### 一、背景介绍与环境配置 在.NET框架中,`System.Web.Mail`命名空间提供了一系列用于发送电子邮件的类。这通常是在早期版本的.NET框架(如.NET Framework...
在本案例中,我们将探讨如何使用`.NET`框架中的`System.Net.Mail`命名空间来实现这一功能,主要涉及以下几个核心知识点: 1. **邮件消息类(MailMessage)**: `MailMessage`是`.NET`中用于封装邮件信息的类,它...
这个命名空间虽然主要设计用于ASP.NET,但在桌面应用中也能工作,不过在.NET Framework 4.0之后,推荐使用System.Net.Mail命名空间,因为它是为桌面和Web应用都优化过的。 下面是一段使用System.Web.Mail发送邮件的...
using System.Net.Mail; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } //当一个用户进行注册的时候同时发送一个邮件到注册人的邮箱,...
然而,对于新的开发,更推荐使用`System.Net.Mail`命名空间,它提供了更现代且功能更全面的邮件处理API,包括对SMTP、POP3和IMAP的支持。 总的来说,虽然`System.Web.Mail`在某些场景下仍然有用,但其局限性(如不...
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); message.SubjectEncoding = System.Text.Encoding.UTF8; message.BodyEncoding = System.Text.Encoding.UTF8; message.From = new ...
“{“success”:false,”message”:”错误System.Net.Mail.SmtpException: Failure sending mail. —> System.Net.WebException: The remote name could not be resolved: ‘smtp.163.com’ 分析: 邮件发送相关...
System.Net.Mail提供了一组类,如SmtpClient和MailMessage,用于构建和发送电子邮件。然而,在实际应用中,开发者可能会遇到各种挑战和陷阱,比如配置问题、权限限制、安全策略等。 描述中提到了EazyEmail,这是一...
2. **网络通信**:使用System.Net.Sockets或System.Net.Mail类库进行TCP/IP通信,与短信网关建立连接。 3. **API调用**:可能通过HTTP请求或者特定的API接口(如RESTful API)与短信服务提供商进行交互。 4. **异步...
mail.Priority = System.Net.Mail.MailPriority.Normal mail.IsBodyHtml = True mail.Body = "这是一封测试邮件" ``` 其中,`Subject`属性设置邮件主题,`SubjectEncoding`和`BodyEncoding`属性分别设置主题和邮件...
MailSystem.NET 是一款基于C#语言开发的开源邮件系统,其特色在于同时提供了WEB版本和桌面应用,为用户提供了灵活多样的访问方式。该系统的核心功能包括对POP3、SMTP和IMAP协议的支持,使得用户能够方便地进行邮件的...
另外,需要注意的是,`System.Web.Mail`命名空间在.NET Framework 2.0之后被弃用,取而代之的是`System.Net.Mail`命名空间。`System.Net.Mail`提供了更现代、功能更全面的`MailMessage`和`SmtpClient`类。尽管如此,...
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(); ``` - **创建SMTP客户端对象**:通过`System.Net.Mail.SmtpClient`类创建一个SMTP客户端实例。这个实例将用于与邮件服务器进行通信。 ##...