public class ToEmial
{
string _to;
string _title;
string _content;
string _strHost;
string _strAccount;
string _strPwd;
string _strFromName;
string _strFrom;
public string To
{
set { _to = value; }
get { return _to; }
}
public string Title
{
set { _title = value; }
get { return _title; }
}
public string Content
{
set { _content = value; }
get { return _content; }
}
public string Host
{
set { _strHost = value; }
get { return _strHost; }
}
public string Account
{
set { _strAccount = value; }
get { return _strAccount; }
}
public string Pwd
{
set { _strPwd = value; }
get { return _strPwd; }
}
public string FromName
{
set { _strFromName = value; }
get { return _strFromName; }
}
public string EmailFrom
{
set { _strFrom = value; }
get { return _strFrom; }
}
public int sendmail()
{
/*
* 反回错误定议yxy //sql8.net
* 1001 发送成功 yxy //sql8.net
* 1002 发送失败yxy //sql8.net
* 1003 STMP服务器地址不能为空yxy //sql8.net
* 1004 SMTP服务帐号yxy //sql8.net
* 1005 发件人名称yxy //sql8.net
* 1006 SMTP服务密码yxy //sql8.net
* 1007 发送方邮件地址yxy //sql8.net
* 2001 收信地址yxy //sql8.net
* 2002 主题yxy //sql8.net
* 2003 内容yxy //sql8.net
*/
if (Host == "")
{
return 1003;
}
if (Account == "")
{
return 1004;
}
if (FromName == "")
{
return 1005;
}
if (Pwd == "")
{
return 1006;
}
if (EmailFrom == "")
{
return 1007;
}
if (To=="")
{
return 2001;
}
if (Title == "")
{
return 2002;
}
if (Content == "")
{
return 2003;
}
MailAddress from = new MailAddress(EmailFrom, FromName);
SmtpClient _smtpClient = new SmtpClient();
_smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式 yxy //sql8.net
_smtpClient.Host = Host; ;//指定SMTP服务器yxy //sql8.net
_smtpClient.Credentials = new System.Net.NetworkCredential(Account, Pwd);//用户名和密码yxy //sql8.net
MailMessage _mailMessage = new MailMessage();
_mailMessage.From = from;
_mailMessage.To.Add(To);
_mailMessage.Subject = Title;//主题yxy //sql8.net
_mailMessage.Body = Content;//内容yxy //sql8.net
_mailMessage.BodyEncoding = System.Text.Encoding.UTF8;//正文编码yxy //sql8.net
_mailMessage.IsBodyHtml = true;//设置为HTML格式yxy //sql8.net
_mailMessage.Priority = MailPriority.High;//优先级yxy //sql8.net
try
{
_smtpClient.Send(_mailMessage);
return 1001;
}
catch
{
return 1002;
}
}
}
--------------------------------------------------------------------------------------
Maticsoft.Functions.ToEmial myemial = new Maticsoft.Functions.ToEmial();
myemial.To = "49262913@qq.com";
myemial.Title = "标题 yxy //sql8.net";
myemial.Content = "内容 yxy //sql8.net";
myemial.Host = "smtp.163.com";
myemial.Account = "49262913@163.com";
myemial.EmailFrom = "49262913@163.com";
myemial.FromName = "SQL吧sql8.net";
myemial.Pwd = "****";
Response.Write(myemial.sendmail().ToString());
本文为黑鹰原创 首发SQL吧 http://sql8.net http://yangxiaoyong.com 转载请注明出处
本文来至SQL吧技术百科 专注技术教程:Http://sql8.net 原文地址:http://www.sql8.net/Programming/NET/Csharp/201002/58953.html