在线发送邮件问题..
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
大家帮忙看看是哪里的问题??谢谢