发送邮件的方法
来源:百度文库 编辑:神马文学网 时间:2024/04/27 17:16:56
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Mail;//发送邮件的命名空间
//using System.Net.Mail;
using System.Text.RegularExpressions;//regex命名空间
///
///SendEmail 的摘要说明///
public class SendEmail
{
public SendEmail()
{ }
public static int F_MailSend(string _strFrom, string _strTo, string _strSubject, string _strBody, string _usename, string _userpwd)
{
///函数作用:发送邮件 ///传入参数:发信人邮箱、收信人邮箱、主题、内容、发信邮箱用户名、发信邮箱密码 ///返 回 值:0为失败;1为成功 //-----验证邮箱的正则表达式------------------------------------------------
string _strRegex = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
MailMessage mail = new MailMessage();
//验证收件人地址是否正确
if (!Regex.IsMatch(_strTo, _strRegex))
{
return 0;
}
else
{
mail.To=_strTo;
} //验证发件人地址是否正确
if (!Regex.IsMatch(_strFrom, _strRegex))
{
return 0;
}
else
{
mail.From = _strFrom;
} //验证主题是否为空
if (_strSubject == null || _strSubject == "")
{
return 0;
}
else
{
mail.Subject = _strSubject;
} //验证邮件内容是否为空
if (_strBody == null || _strBody == "")
{
return 0;
}
else
{
mail.Body = _strBody;
}
mail.Priority = MailPriority.High; //邮件级别,.High、.Low、.Normal
mail.BodyFormat = MailFormat.Html; //邮件形式,.Text、.Html
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", _usename); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", _userpwd); //set your password here
SmtpMail.SmtpServer = "smtp.163.com"; //your real server goes here smtp.163.com
try
{
SmtpMail.Send(mail);
return 1;
}
catch
{
return 0;
}
}
}
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Mail;//发送邮件的命名空间
//using System.Net.Mail;
using System.Text.RegularExpressions;//regex命名空间
///
///SendEmail 的摘要说明///
public class SendEmail
{
public SendEmail()
{ }
public static int F_MailSend(string _strFrom, string _strTo, string _strSubject, string _strBody, string _usename, string _userpwd)
{
///函数作用:发送邮件 ///传入参数:发信人邮箱、收信人邮箱、主题、内容、发信邮箱用户名、发信邮箱密码 ///返 回 值:0为失败;1为成功 //-----验证邮箱的正则表达式------------------------------------------------
string _strRegex = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*";
MailMessage mail = new MailMessage();
//验证收件人地址是否正确
if (!Regex.IsMatch(_strTo, _strRegex))
{
return 0;
}
else
{
mail.To=_strTo;
} //验证发件人地址是否正确
if (!Regex.IsMatch(_strFrom, _strRegex))
{
return 0;
}
else
{
mail.From = _strFrom;
} //验证主题是否为空
if (_strSubject == null || _strSubject == "")
{
return 0;
}
else
{
mail.Subject = _strSubject;
} //验证邮件内容是否为空
if (_strBody == null || _strBody == "")
{
return 0;
}
else
{
mail.Body = _strBody;
}
mail.Priority = MailPriority.High; //邮件级别,.High、.Low、.Normal
mail.BodyFormat = MailFormat.Html; //邮件形式,.Text、.Html
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", _usename); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", _userpwd); //set your password here
SmtpMail.SmtpServer = "smtp.163.com"; //your real server goes here smtp.163.com
try
{
SmtpMail.Send(mail);
return 1;
}
catch
{
return 0;
}
}
}
发送邮件的方法
发送Email邮件方法总结
C#发送Email邮件三种方法的总结
发送邮件
如何发送大容量的邮件?
如何免费发送1GB邮件?----适合用来发送体积庞大的邮件
Outlook定时发送邮件
c#socket发送邮件
用C++写一发送邮件的程序
c#socket发送邮件详解
Spring发送邮件简单实例
使用SMTP命令发送邮件
《pro Spring》学习笔记之使用Spring+James邮件服务器发送内嵌图片的HTML邮件(转载)
无需注册可发送匿名邮件的邮箱服务 - 免费邮箱 - 东度免费资源网
大容量邮件如何快速发送 - 楚天的日志 - 网易博客
C#发送邮件代码 - 赤色火焰.Net
用Python发送邮件及附件
邮件网盘--快捷发送文件到邮件
超级邮件群发机的破解方法
超级邮件群发机的破解方法
PRCIWBG 电子双周刊 第四期 在Outlook中给您的联系人分分组?实现邮件组发送?
我是盖茨?匿名邮件发送图解全攻略 - MiTriX
利用Jmail发送和接收邮件(C#) - .NET Framework
ASP.Net环境下使用Jmail组件发送邮件