Dotnet1.1&2.0 SendMail detail to explain
2009-04-24 17:26
435 查看
0
/**********************************************************************
**
** DotNet1.1环境下 Code CreateBy 伴老 2005.6.14
** http://blog.csdn.net/abandonship/archive/2008/12/22/3580975.aspx
**
**********************************************************************/
using System.Web.Mail;
public void _Dotnet1.1SendMail()
{
strMessage = ""; //定义错误信息
MailMessage mailMsg = new MailMessage();
mailMsg.From = strMailFrom;
mailMsg.To = strMailTo;
mailMsg.Subject = strMailTitle;
mailMsg.Priority = MailPriority.High; //邮件级别,.High、.Low、.Normal
mailMsg.BodyFormat = MailFormat.Text; //邮件形式,.Text、.Html
mailMsg.Body = strEmailBody;
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //设置支持服务器验证
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", strMailFrom); //设置用户名
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", strPsd); //设置用户密码
SmtpMail.SmtpServer = strMailSMTP; //or SmtpMail.SmtpServer.Insert( 0, strMailSMTP);
try
{
//发送邮件
SmtpMail.Send( mailMsg );
}
catch( Exception Message )
{
strMessage = "发送失败" + Message.Message.ToString();
}
if( strMessage != "" )
{
Response.Write(strMessage );
}
else
{
Response.Write("发送成功!");
}
}
/**********************************************************************
**
** DotNet2.0环境下 Code CreateBy 伴老 2006.11.23
** http://blog.csdn.net/abandonship/archive/2008/12/22/3580975.aspx
**
**********************************************************************/
using System.Net.Mail;
public void _Dotnet2.0SendMail()
{
strMessage = "";
MailMessage mailMsg = new MailMessage();
mailMsg.To.Add(new MailAddress("收件人邮箱集合")); //设置收件人的邮件地址
mailMsg.From = new MailAddress("发件人邮箱地址"); //设置发送者的邮件地址
mailMsg.Subject = strMailTitle; //设置邮件主题
mailMsg.Priority = MailPriority.High; // 设置邮件级别:.High、.Low、.Normal
mailMsg.IsBodyHtml = true; //设置邮件形式:是否为HTML格式
mailMsg.SubjectEncoding = System.Text.Encoding.UTF8;
mailMsg.BodyEncoding = System.Text.Encoding.UTF8;
mailMsg.Body = strEmailHTML;
//设置发送邮件服务器
SmtpClient client = new SmtpClient(strMailSMTPServer);
client.Credentials = new System.Net.NetworkCredential("发件人邮箱", "发件人邮箱密码");
client.EnableSsl = true; //经过SSL加密
try
{
client.Send(mailMsg);
}
catch (Exception Message)
{
strMessage = "发送失败" + Message.Message.ToString();
}
if( strMessage != "" )
{
Response.Write(strMessage );
}
else
{
Response.Write("发送成功!");
}
}
/**********************************************************************
**
** DotNet1.1环境下 Code CreateBy 伴老 2005.6.14
** http://blog.csdn.net/abandonship/archive/2008/12/22/3580975.aspx
**
**********************************************************************/
using System.Web.Mail;
public void _Dotnet1.1SendMail()
{
strMessage = ""; //定义错误信息
MailMessage mailMsg = new MailMessage();
mailMsg.From = strMailFrom;
mailMsg.To = strMailTo;
mailMsg.Subject = strMailTitle;
mailMsg.Priority = MailPriority.High; //邮件级别,.High、.Low、.Normal
mailMsg.BodyFormat = MailFormat.Text; //邮件形式,.Text、.Html
mailMsg.Body = strEmailBody;
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //设置支持服务器验证
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", strMailFrom); //设置用户名
mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", strPsd); //设置用户密码
SmtpMail.SmtpServer = strMailSMTP; //or SmtpMail.SmtpServer.Insert( 0, strMailSMTP);
try
{
//发送邮件
SmtpMail.Send( mailMsg );
}
catch( Exception Message )
{
strMessage = "发送失败" + Message.Message.ToString();
}
if( strMessage != "" )
{
Response.Write(strMessage );
}
else
{
Response.Write("发送成功!");
}
}
/**********************************************************************
**
** DotNet2.0环境下 Code CreateBy 伴老 2006.11.23
** http://blog.csdn.net/abandonship/archive/2008/12/22/3580975.aspx
**
**********************************************************************/
using System.Net.Mail;
public void _Dotnet2.0SendMail()
{
strMessage = "";
MailMessage mailMsg = new MailMessage();
mailMsg.To.Add(new MailAddress("收件人邮箱集合")); //设置收件人的邮件地址
mailMsg.From = new MailAddress("发件人邮箱地址"); //设置发送者的邮件地址
mailMsg.Subject = strMailTitle; //设置邮件主题
mailMsg.Priority = MailPriority.High; // 设置邮件级别:.High、.Low、.Normal
mailMsg.IsBodyHtml = true; //设置邮件形式:是否为HTML格式
mailMsg.SubjectEncoding = System.Text.Encoding.UTF8;
mailMsg.BodyEncoding = System.Text.Encoding.UTF8;
mailMsg.Body = strEmailHTML;
//设置发送邮件服务器
SmtpClient client = new SmtpClient(strMailSMTPServer);
client.Credentials = new System.Net.NetworkCredential("发件人邮箱", "发件人邮箱密码");
client.EnableSsl = true; //经过SSL加密
try
{
client.Send(mailMsg);
}
catch (Exception Message)
{
strMessage = "发送失败" + Message.Message.ToString();
}
if( strMessage != "" )
{
Response.Write(strMessage );
}
else
{
Response.Write("发送成功!");
}
}
相关文章推荐
- Dotnet1.1 and 2.0 SendMail detail to explain
- Note On <Programming Entity Framework 2nd Edition> -02: How to Use SqlExpress Profiler 2.0
- Welcome to Version 2.0 of theForger's Win32 API Tutorial
- ASP.NET 2.0: Add build-in paging feature to repeater/为repeater添加内置分页功能
- How to troubleshoot 'Procedure or function has too many arguments specified' in asp.net 2.0
- 基于hadoop 2.0 的hbase "Unable to load native-hadoop library for your platform" 问题解决
- ASP.NET 2.0: Add build-in paging feature to repeater/为repeater添加内置分页功能
- Loadrunner连接负载机失败,提示"Failed to connect to the load generator.Check the output window for more detail
- warning: push.default is unset; its implicit value has changed in Git 2.0 from 'matching' to 'simple
- The Top command【Detail explain to each item】
- [ASP.NET2.0][数据库更新]How to troubleshoot 'Procedure or function has too many arguments specified' in asp.net 2.0
- 【hibernate】错误:org.hibernate.HibernateException: identifier of an instance of com.agen.entity.Monthdetail was altered from xx to xx
- java&nbsp;string.ToCharArray()的…
- error: No rule to make target `XXXX.ui', needed by 'ui_XXX.h' Stop
- leetcode笔记--Roman to Integer & Integer to Roman
- Swift Compiler Error Binary oprator '+' cannot be applied to operands of type 'UInt16' and 'UInt8'
- error C2440: 'static_cast' : cannot convert from 'void (__thiscall CMainFrame::* )(void)' to 'LRESUL
- c++builder 2010 [ILINK32 Error] Fatal: Unable to open file 'xxxxxx.OBJ'
- Spark 2.0 DataFrame map操作中Unable to find encoder for type stored in a Dataset.问题的分析与解决
- Android Studio Error : Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled