在线发送邮件问题..

dys_198102 2009-01-07 01:44:21
SysMailMessage.cs类文件代码如下:
using System;
using System.Text;

namespace Forum.BLL.Other
{

#region .net邮件发送程
public class SysMailMessage
{
private string _subject;
private string _body;
private string _from;
private string _fromName;
private string _recipientName;
private string _mailDomain;
private int _mailserverport=25;
private string _username;
private string _password;
private bool _html=true;
private string _recipient;
private bool _usedefaultcredentials = false;

public SysMailMessage()
{ }

/// <summary>
/// 邮件主题
/// </summary>
public string Subject
{
get { return this._subject; }
set { this._subject = value; }
}

/// <summary>
/// 邮件正文
/// </summary>
public string Body
{
get { return this._body; }
set { this._body = value; }
}


/// <summary>
/// 发件人地址
/// </summary>
public string From
{
get { return _from; }
set { this._from = value; }
}


/// <summary>
/// 发件人姓名
/// </summary>
public string FromName
{
get { return this._fromName; }
set { this._fromName = value; }
}


/// <summary>
/// 收件人姓名
/// </summary>
public string RecipientName
{
get { return this._recipientName; }
set { this._recipientName = value; }
}

/// <summary>
/// 邮箱域
/// </summary>
public string MailDomain
{
get { return this._mailDomain; }
set { this._mailDomain = value; }
}

/// <summary>
/// 邮件服务器端口号
/// </summary>
public int MailDomainPort
{
set { this._mailserverport = value; }
get { return this._mailserverport; }
}


/// <summary>
/// SMTP认证时使用的用户名
/// </summary>
public string MailServerUserName
{
set
{
if (value.Trim() != "")
{
this._username = value.Trim();
}
else
{
this._username = "";
}
}
get { return _username; }
}

/// <summary>
/// SMTP认证时使用的密码
/// </summary>
public string MailServerPassWord
{
set { this._password = value; }
get { return _password; }
}

/// <summary>
/// 是否Html邮件
/// </summary>
public bool Html
{
get { return this._html; }
set { this._html = value; }
}

/// <summary>
/// 是否加密验证
/// </summary>
public bool UseDefaultCredentials
{
get { return this._usedefaultcredentials; }
set { this._usedefaultcredentials = value; }
}

//收件人的邮箱地址
public bool AddRecipient(params string[] username)
{
//this._recipient= null;
this._recipient = username[0].Trim();

return true;
}

/// <summary>
/// 发送
/// </summary>
/// <returns></returns>
public bool Send()
{

System.Net.Mail.MailMessage myEmail = new System.Net.Mail.MailMessage();
Encoding eEncod = Encoding.GetEncoding("utf-8");
myEmail.From = new System.Net.Mail.MailAddress(this.From, this.Subject, eEncod);
myEmail.To.Add(this._recipient);
myEmail.Subject = this.Subject;
myEmail.Body = this.Body;
myEmail.Priority = System.Net.Mail.MailPriority.Normal;
myEmail.BodyEncoding = eEncod;;
myEmail.IsBodyHtml = this.Html; //邮件形式,.Text、.Html


System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
smtp.Host = this.MailDomain;
smtp.Port = this.MailDomainPort;
smtp.Credentials = new System.Net.NetworkCredential(this.MailServerUserName, this.MailServerPassWord);
smtp.UseDefaultCredentials = this.UseDefaultCredentials;
//smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

//当不是25端口(gmail:587)
if (this.MailDomainPort != 25)
{
smtp.EnableSsl = true;
}
//System.Web.Mail.SmtpMail.SmtpServer = this.MailDomain;

try
{
smtp.Send(myEmail);
}
catch (System.Net.Mail.SmtpException e)
{
string result = e.Message;
return false;
}

return true;
}
}
#endregion

#region 使用方法
//Forum.Mail.SysMailMessage mg = new Forum.Mail.SysMailMessage();

//mg.Body ="邮件内容";

//mg.From = model_2.Name;// "email@jingdiansheji.com";// "hanbing81868164@163.com";
//mg.FromName = model_2.Name.ToLower().Split('@')[0];// "email";
//mg.Html = true;
//mg.MailDomainPort = 25;

//mg.MailServerPassWord = pwd_;// "email";
//mg.MailServerUserName = mg.FromName;// "email";
//mg.Subject = model_3.Name;


//mg.AddRecipient(tomail);
//mg.RecipientName = tomail;
//mg.MailDomain = model_2.Tname;// "60.190.222.222";
#endregion
}
测试页面只有一个按钮.CS文件代码如下
protected void Button1_Click1(object sender, EventArgs e)
{
Forum.BLL.Other.SysMailMessage mg = new Forum.BLL.Other.SysMailMessage();
mg.Subject = "kkkkkkkkkkk";
mg.Body = "sdafadsf";

mg.From = "dys_198102@163.com";//"hanbing81868164@163.com";
mg.FromName = "dys_198102@163.com"; // "email";
mg.Html = false;
mg.MailDomainPort = 25;

mg.MailServerPassWord = "010000";// "email";
mg.MailServerUserName = "dys_198102";// "email";
mg.Subject ="你好";


mg.AddRecipient("dys_198102@yahoo.com.cn");
mg.RecipientName ="390238244";
mg.MailDomain = "yahoo.com.cn";// "60.190.222.222";
mg.Send();
Response.Write("<script language='javascript'>alert('ok');</script>");
}
能正常运行,但收不到邮件
测试地址:http://dys198102.w43.cndns.com/webtest/test.aspx
大家帮忙看看是哪里的问题??谢谢
...全文
395 28 打赏 收藏 转发到动态 举报
写回复
用AI写文章
28 条回复
切换为时间正序
请发表友善的回复…
发表回复
dys_198102 2009-01-08
  • 打赏
  • 举报
回复
不用AJAX就可以传值了,不过有一个用C#验证EMAIL的程序,
public static bool IsEmail(string str_Email)
{
return System.Text.RegularExpressions.Regex.IsMatch(str_Email, @"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
}
这是在网站看别人的.

protected void Button1_Click1(object sender, EventArgs e)
{
string tt = TextBox2.Text.ToString().Trim();
if (this.TextBox1.Text.ToString() == "" || this.TextBox2.Text.ToString() == "" || this.TextBox3.Text.ToString() == "")
{
this.Label2.Text = "The title of your mailbox, mail content can not be empty!";
}
[color=#FF0000] else if (IsEmail(tt))
{
this.Label2.Text = "You have entered an incorrect e-mail format!";
}如果随便输入字符,这部分没运行,应报错才对.这里怎么用IsEmail()[/color]
else
{
winner2050 2009-01-08
  • 打赏
  • 举报
回复
 /// <summary>
/// 发送邮件
/// </summary>
/// <param name="Subject"></param>
/// <param name="Body"></param>
/// <param name="To"></param>
/// <param name="MailFrom"></param>
/// <param name="MailFromName"></param>
/// <param name="MailDomain"></param>
/// <param name="MailServerUserName"></param>
/// <param name="MailServerPassWord"></param>
/// <returns></returns>
public bool Send(string Subject, string Body, string To, string MailFrom, string MailFromName, string MailDomain, string MailServerUserName, string MailServerPassWord)
{
try
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress(MailFrom, MailFromName);
msg.To.Add(new MailAddress(To, To));

msg.Subject = Subject;
msg.Body = Body;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.Normal;
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.Headers.Add("X-Priority", "3");
msg.Headers.Add("X-MSMail-Priority", "Normal");
msg.Headers.Add("X-Mailer", "Microsoft Outlook Express 6.00.2900.2869");
msg.Headers.Add("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2869");
msg.Headers.Add("ReturnReceipt", "1");

SmtpClient client = new SmtpClient(MailDomain);
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(MailServerUserName, MailServerPassWord); //帐号密码
client.DeliveryMethod = SmtpDeliveryMethod.Network;

client.Send(msg);
return true;
}
catch { return false; }
}
glt3260053 2009-01-08
  • 打赏
  • 举报
回复
[Quote=引用 20 楼 dys_198102 的回复:]
现在可以发送邮件了.就是那个从数据库中提取数据传值那.有问题....
[/Quote]

说下问题在哪里啊!
dys_198102 2009-01-08
  • 打赏
  • 举报
回复
楼上的兄弟肯定没有最后发的几条,现在的问题是页面加载时打开数据库把值付给公共变量.当提交时运用AJAXPRO发邮件.提交时公共变量没有值为空,也就是说值没有传过来.
[AjaxPro.AjaxMethod]
public string sendemails(string title,string email,string body)
{
MailMessage mailMessage = new MailMessage();
string strBody;

//发送地址
mailMessage.From = new MailAddress(sendemail);

//接收地址
mailMessage.To.Add(j_email);

//邮件标题
mailMessage.Subject = "测试";

mailMessage.BodyEncoding = System.Text.Encoding.UTF8;

//邮件内容
strBody = "测试哈哈!!傻样....";
mailMessage.Body = strBody.Trim();

SmtpClient smtpClient = new SmtpClient();
//smtpClient.EnableSsl = true; //Smtp服务器
smtpClient.Host = smtp;

//Smtp服务器发送端口
smtpClient.Port = 25;

//发送用户名及密码
smtpClient.Credentials = new NetworkCredential("dys_198102", "23");

return j_email;
//try
//{
// //调用发送函数
// smtpClient.Send(mailMessage);
// return title = "true";
//}
//catch(Exception ex)
//{
// string tempex = ex.ToString();
// return title = sendemail+" <br />"+j_email+" <br />"+smtp;
// // return title ="false";
//}
} 红色的变量为空
sh_suyuelin 2009-01-08
  • 打赏
  • 举报
回复
这个问题不久前我遇到过。。邮件问题。换邮箱
dys_198102 2009-01-08
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 zerostyle 的回复:]
页面生存时间的问题,ajax调用可以看作是一个static的方法或者是一个webservice,在你请求发过去的时候,页面类 test 的实例已经不存在了,怎么调用的到?
[/Quote]引用错了,是这位的话
dys_198102 2009-01-08
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 dys_198102 的回复:]
问个低级的问题,为什么我设置了全局变量,而 [AjaxPro.AjaxMethod]里获得的变量是空的...给点思路谢谢.

public partial class test : System.Web.UI.Page
{
public string smtp,sendemail,password,j_email,senduser;
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(test));
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = Syste…
[/Quote]这位老兄说了,现在正在想怎么解决
hongqi162 2009-01-08
  • 打赏
  • 举报
回复
有问题?什么问题?
dys_198102 2009-01-08
  • 打赏
  • 举报
回复
现在可以发送邮件了.就是那个从数据库中提取数据传值那.有问题....
lovehongyun 2009-01-08
  • 打赏
  • 举报
回复
换个邮箱试试.

我用System.Net.Mail.SmtpClient发邮件都可以正常发送.
zerostyle 2009-01-08
  • 打赏
  • 举报
回复
页面生存时间的问题,ajax调用可以看作是一个static的方法或者是一个webservice,在你请求发过去的时候,页面类 test 的实例已经不存在了,怎么调用的到?
dys_198102 2009-01-08
  • 打赏
  • 举报
回复
问个低级的问题,为什么我设置了全局变量,而 [AjaxPro.AjaxMethod]里获得的变量是空的...给点思路谢谢.

public partial class test : System.Web.UI.Page
{
public string smtp,sendemail,password,j_email,senduser;
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(test));
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["webtest"].ConnectionString;
conn.Open();

string sqls = "select * from [Hover_Admin]";
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = sqls;

OleDbDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
sendemail = dr["email"].ToString().Trim();
password = dr["password"].ToString().Trim();
smtp = dr["smtp"].ToString().Trim();
j_email = dr["j_email"].ToString().Trim();
senduser = dr["u_user"].ToString().Trim();

}
dr.Dispose();
dr = null;
conn.Dispose();
conn.Close();
}



[AjaxPro.AjaxMethod]
public string sendemails(string title,string email,string body)
{
MailMessage mailMessage = new MailMessage();
string strBody;

//发送地址
mailMessage.From = new MailAddress(sendemail);

//接收地址
mailMessage.To.Add(j_email);

//邮件标题
mailMessage.Subject = "测试";

mailMessage.BodyEncoding = System.Text.Encoding.UTF8;

//邮件内容
strBody = "测试哈哈!!傻样....";
mailMessage.Body = strBody.Trim();

SmtpClient smtpClient = new SmtpClient();
//smtpClient.EnableSsl = true; //Smtp服务器
smtpClient.Host = smtp;

//Smtp服务器发送端口
smtpClient.Port = 25;

//发送用户名及密码
smtpClient.Credentials = new NetworkCredential("dys_198102", "23");

return j_email;
//try
//{
// //调用发送函数
// smtpClient.Send(mailMessage);
// return title = "true";
//}
//catch(Exception ex)
//{
// string tempex = ex.ToString();
// return title = sendemail+"<br />"+j_email+"<br />"+smtp;
// // return title ="false";
//}
}


}
skeljy 2009-01-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sy_binbin 的回复:]
现在很多邮箱都不支持SMTP发信了

163的那个邮箱是啥时候申请的,要是2007年之前的还可以发信,2007年后申请的新用户都不可以发信了
[/Quote]

同意!
zerostyle 2009-01-07
  • 打赏
  • 举报
回复
/// <summary>
/// 使用System.Net.Mail.SmtpClient对象,附带邮件抄送功能,请使用相应的本类构造函数即可构造抄送邮件
/// </summary>
public void sengmill_net()
{
try
{
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(this.FromSmtp);
if (this.SmtpUseSsl)
{
client.EnableSsl = true;
}
if (this.SmtpPort != 25)
{
client.Port = this.SmtpPort;
}
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(this.FromUserName, this.FromUserPasswd);
client.DeliveryMethod = SmtpDeliveryMethod.Network;

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
if (this.FromName != string.Empty)
{
mail.From = new MailAddress(this.From, this.FromName);
}
else
{
mail.From = new MailAddress(this.From);
}

if (this.ReplyTo.Trim() != string.Empty && this.CC.IndexOf(',') > 0)
{
mail.ReplyTo = new MailAddress(this.ReplyTo);

string[] tos = this.CC.Split(',');
foreach (string rt in tos)
{
mail.CC.Add(rt);
}

}
else
{
string[] tos = this.To.Split(',');
foreach (string to in tos)
{
mail.To.Add(to);
}
}

mail.Subject = this.Title;
mail.Body = this.Content;
mail.BodyEncoding = this.Encoding;
mail.IsBodyHtml = this.IsBodyHtml;
//client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
//client.SendAsync(mail,"");
client.Send(mail);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}

void client_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
bool mailSent = true;

// System.Net.Mail.MailMessage mail = (System.Net.Mail.MailMessage)e.UserState;
// string subject = mail.Subject;
// string content = mail.Body;

if (e.Cancelled)
{
mailSent = false;
}
if (e.Error != null)
{
mailSent = false;
}
if (!mailSent)
{
//string file = "Send Mail/Send Mail test asnc Error " + System.DateTime.Now.ToString("yyyy-MM-dd") + ".txt";

StringBuilder sb = new StringBuilder();
sb.Append("Send Failed! ");
//sb.Append("Subject :" + subject + " ");
//sb.Append("Content :" + content);
sb.Append("Exception :" + e.Error.ToString());
string s = sb.ToString();
}
else
{
//string file = "Send Mail/Send Mail test asnc Error " + System.DateTime.Now.ToString("yyyy-MM-dd") + ".txt";

StringBuilder sb = new StringBuilder();
sb.Append("Send Sucess! ");
//sb.Append("Subject :" + subject + " ");
//sb.Append("Content :" + content);
string s = sb.ToString();
}


}

#endregion

}

public class MailSendEventArgs : EventArgs
{
public MailSendEventArgs(MailSend ms)
{
this.mailSend = ms;
}

private MailSend mailSend;

public MailSend MailSend
{
get
{
return MailSend;
}
}

}


}

//回复太快!如果你是恶意刷楼,将会受到严厉惩罚!
//娘来,可写的内容写不开,还不让连续发,楼主,这分要是不给我我可真伤心了。。。等ING


HBJMSHOP 2009-01-07
  • 打赏
  • 举报
回复
业务很复杂啊
zerostyle 2009-01-07
  • 打赏
  • 举报
回复
/// <summary>
/// 使用System.Net.Mail.SmtpClient对象,附带邮件抄送功能,请使用相应的本类构造函数即可构造抄送邮件
/// </summary>
public void sengmill_net()
{
try
{
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(this.FromSmtp);
if (this.SmtpUseSsl)
{
client.EnableSsl = true;
}
if (this.SmtpPort != 25)
{
client.Port = this.SmtpPort;
}
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(this.FromUserName, this.FromUserPasswd);
client.DeliveryMethod = SmtpDeliveryMethod.Network;

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
if (this.FromName != string.Empty)
{
mail.From = new MailAddress(this.From, this.FromName);
}
else
{
mail.From = new MailAddress(this.From);
}

if (this.ReplyTo.Trim() != string.Empty && this.CC.IndexOf(',') > 0)
{
mail.ReplyTo = new MailAddress(this.ReplyTo);

string[] tos = this.CC.Split(',');
foreach (string rt in tos)
{
mail.CC.Add(rt);
}

}
else
{
string[] tos = this.To.Split(',');
foreach (string to in tos)
{
mail.To.Add(to);
}
}

mail.Subject = this.Title;
mail.Body = this.Content;
mail.BodyEncoding = this.Encoding;
mail.IsBodyHtml = this.IsBodyHtml;
//client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
//client.SendAsync(mail,"");
client.Send(mail);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}

void client_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
bool mailSent = true;

// System.Net.Mail.MailMessage mail = (System.Net.Mail.MailMessage)e.UserState;
// string subject = mail.Subject;
// string content = mail.Body;

if (e.Cancelled)
{
mailSent = false;
}
if (e.Error != null)
{
mailSent = false;
}
if (!mailSent)
{
//string file = "Send Mail/Send Mail test asnc Error " + System.DateTime.Now.ToString("yyyy-MM-dd") + ".txt";

StringBuilder sb = new StringBuilder();
sb.Append("Send Failed! ");
//sb.Append("Subject :" + subject + " ");
//sb.Append("Content :" + content);
sb.Append("Exception :" + e.Error.ToString());
string s = sb.ToString();
}
else
{
//string file = "Send Mail/Send Mail test asnc Error " + System.DateTime.Now.ToString("yyyy-MM-dd") + ".txt";

StringBuilder sb = new StringBuilder();
sb.Append("Send Sucess! ");
//sb.Append("Subject :" + subject + " ");
//sb.Append("Content :" + content);
string s = sb.ToString();
}


}

#endregion

}

public class MailSendEventArgs : EventArgs
{
public MailSendEventArgs(MailSend ms)
{
this.mailSend = ms;
}

private MailSend mailSend;

public MailSend MailSend
{
get
{
return MailSend;
}
}

}


}



zerostyle 2009-01-07
  • 打赏
  • 举报
回复
/// <summary>
/// 邮件标题
/// </summary>
public string Title
{
get
{
return title;
}
set
{
title = value;
}
}

private string content = string.Empty;

/// <summary>
/// 邮件内容
/// </summary>
public string Content
{
get
{
return content;
}
set
{
content = value;
}
}

private Encoding encoding = Encoding.UTF8;

/// <summary>
/// 邮件编码方式;默认UTF8
/// </summary>
public Encoding Encoding
{
get
{
return encoding;
}
set
{
encoding = value;
}
}


private bool smtpUseSsl = false;

/// <summary>
/// 邮件服务器是否需要验证,默认不验证
/// </summary>
public bool SmtpUseSsl
{
get
{
return smtpUseSsl;
}
set
{
smtpUseSsl = value;
}
}

private int smtpPort = 25;

/// <summary>
/// SMTP端口,默认是25
/// </summary>
public int SmtpPort
{
get
{
return smtpPort;
}
set
{
smtpPort = value;
}
}



private bool isBodyHtml = true;

/// <summary>
/// 是否是HTML方式;默认是
/// </summary>
public bool IsBodyHtml
{
get
{
return isBodyHtml;
}
set
{
isBodyHtml = value;
}
}

#endregion

#region 事件

public delegate void MailSendHandler(object sender, MailSendEventArgs e);


public event MailSendHandler OnSendBefore;

public event MailSendHandler OnSendFinish;

#endregion

#region 方法

/// <summary>
/// 邮件发送的方法
/// </summary>
/// <returns></returns>
public bool Send()
{
try
{
MailSendEventArgs msea = new MailSendEventArgs(this);
if (this.OnSendBefore != null)
{
this.OnSendBefore(this, msea);
}

this.sengmill_net();

//MailSendEventArgs msea = new MailSendEventArgs(this);
if (this.OnSendFinish != null)
{
this.OnSendFinish(this, msea);
}
return true;
}
catch (Exception ex)
{
return false;
//throw new Exception(ex.Message);
}

}
/// <summary>
/// 使用System.Web.Mail.MailMessage对象
/// </summary>
public void sengmill_web()
{
try
{
//.net smtp类进行邮件发送,支持认证,附件添加;
System.Web.Mail.MailMessage mailmsg = new System.Web.Mail.MailMessage();
mailmsg.From = this.From;
mailmsg.To = this.To;
mailmsg.Body = this.Content;
mailmsg.Subject = this.Title;
mailmsg.BodyEncoding = this.Encoding;
//是否需要验证,一般是要的
if (this.SmtpUseSsl)
{
mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");//

}
mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//自己邮箱的用户名
mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", this.FromUserName);
//自己邮箱的密码
mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", this.FromUserPasswd);

//邮箱的端口
if (this.SmtpPort != 25)
{
mailmsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", this.SmtpPort);
}

System.Web.Mail.SmtpMail.SmtpServer = this.FromSmtp;
System.Web.Mail.SmtpMail.Send(mailmsg);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}

}


zerostyle 2009-01-07
  • 打赏
  • 举报
回复
给你个前几天写的,提供两种方式发送邮件,一种是使用System.Web.Mail命名空间,另一种是用System.Net.Mail命名空间

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.Mail;
using System.Net.Mail;
namespace ZeroStyle.Common
{
/*///////////////////////////////////////////////////////////////////
// cuiliang 2008/05/30
//
// E-Mail:zerostyle@126.com
//
// QQ:83226227
//
*/
///////////////////////////////////////////////////////////////////

/// <summary>
/// 站点发送邮件的类
/// </summary>
public class MailSend
{

#region 构造

public MailSend()
{

}

/// <summary>
///
/// </summary>
/// <param name="from">发件人邮箱地址</param>
/// <param name="to">收件人邮件地址</param>
/// <param name="fromUserName">发件人用户名</param>
/// <param name="fromUserPasswd">发件人密码</param>
/// <param name="fromSmtp">发邮件的 smtp 服务器</param>
/// <param name="title">邮件标题</param>
public MailSend(string from, string to, string fromUserName, string fromUserPasswd, string fromSmtp, string title)
{
this.From = from;
this.To = to;
this.FromUserName = fromUserName;
this.FromUserPasswd = fromUserPasswd;
this.FromSmtp = fromSmtp;
this.Title = title;
}

/// <summary>
/// 邮件抄送功能
/// </summary>
/// <param name="from">发件人邮箱地址</param>
/// <param name="cc">抄送人</param>
/// <param name="cc">抄送收件人,多个用","分隔</param>
/// <param name="fromUserName">发件人用户名</param>
/// <param name="fromUserPasswd">发件人密码</param>
/// <param name="fromSmtp">发邮件的 smtp 服务器</param>
/// <param name="title">邮件标题</param>
public MailSend(string from, string replyTo, string cc, string fromUserName, string fromUserPasswd, string fromSmtp, string title)
{
this.From = from;
this.ReplyTo = replyTo;
this.CC = cc;
this.FromUserName = fromUserName;
this.FromUserPasswd = fromUserPasswd;
this.FromSmtp = fromSmtp;
this.Title = title;
}

#endregion

#region 属性

private string from = string.Empty;

/// <summary>
/// 发件人邮箱地址
/// </summary>
public string From
{
get
{
return from;
}
set
{
from = value;
}
}

private string fromName;

/// <summary>
/// 显示在收件人邮件中的发件人名称(非邮件地址)
/// </summary>
public string FromName
{
get
{
return fromName;
}
set
{
fromName = value;
}
}

private string to = string.Empty;

/// <summary>
/// 收件人邮件地址
/// </summary>
public string To
{
get
{
return to;
}
set
{
to = value;
}
}

private string replyTo = string.Empty;

/// <summary>
/// 抄送人
/// </summary>
public string ReplyTo
{
get
{
return replyTo;
}
set
{
replyTo = value;
}
}

private string cc = string.Empty;

/// <summary>
/// 抄送收件人
/// </summary>
public string CC
{
get
{
return cc;
}
set
{
cc = value;
}
}

private string fromUserName = string.Empty;

/// <summary>
/// 发件人用户名
/// </summary>
public string FromUserName
{
get
{
return fromUserName;
}
set
{
fromUserName = value;
}
}

private string fromUserPasswd;

/// <summary>
/// 发件人密码
/// </summary>
public string FromUserPasswd
{
get
{
return fromUserPasswd;
}
set
{
fromUserPasswd = value;
}
}

private string fromSmtp = string.Empty;

/// <summary>
/// 发邮件的 smtp 服务器
/// </summary>
public string FromSmtp
{
get
{
return fromSmtp;
}
set
{
fromSmtp = value;
}
}

private string title = string.Empty;

bj890 2009-01-07
  • 打赏
  • 举报
回复
换个邮箱呢!
dys_198102 2009-01-07
  • 打赏
  • 举报
回复
楼上的兄弟,代码给全了吗,为什么我返回的false ,发送失败.....
加载更多回复(8)

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧