日期:2014-05-19  浏览次数:20476 次

.net2.0发送邮件问题
配置文件里我这么写的
<system.net>
        <mailSettings>
            <smtp   from= "tss19841011@sina.com ">
                <network   port= "25 "   userName= "我的邮箱用户名 "   password= "我的邮箱密码 "   defaultCredentials= "true "   host= "smtp.sina.com "/>
            </smtp>
        </mailSettings>
    </system.net>

这是事件代码
MailMessage   m_message   =   new   MailMessage();

                m_message.From   =   new   MailAddress( "tss19841011@sina.com ");

                m_message.To.Add(new   MailAddress( "tss19841011@sina.com "));

                m_message.Subject   =   "test ";

                m_message.Body   =   "hello   ";

                SmtpClient   m_smtpClient   =   new   SmtpClient();

                m_smtpClient.Send(m_message);
试了很多方法都报错...求高手解决   或者提供点别的出路   实在感激不尽   100分送上

------解决方案--------------------
public Boolean sendemail()
{
_fromadr = "tss19841011@163.com ";
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(_fromadr,_sendadr,_title,_content);
message.IsBodyHtml = true;
message.BodyEncoding = System.Text.Encoding.Default;
if (_bcadr != null)
{
message.CC.Add(_bcadr);
}
if (_filename != null)
{
System.Net.Mail.Attachment data = new System.Net.Mail.Attachment(_filename, System.Net.Mime.MediaTypeNames.Application.Octet);
System.Net.Mime.ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(_filename);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(_filename);
disposition.ReadDate = System.IO.File.GetLastAccessTime(_filename);
message.Attachments.Add(data);
}
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient( "smtp.163.com ");
client.Credentials = new NetworkCredential( "tss19841011 ", "*password* ");//这个要你的163的用户名和密码
try
{
client.Send(message);
return true;
}
catch (Exception ex)
{
_errormsg = ex.Message;
return false;
}

}

补充说一下,我式过sina的服务器不行,163.com的可以发~
------解决方案--------------------
/// <summary>
/// 发送邮件
/// </summary>
/// <param name= "strSmtpServer "> smtp地址 </param>
/// <param name= "UserName "> 用户名 </param>
/// <param name= "Password "> 密码 </param>
/// <param name= "strFrom "> 发信人地址 </param>
/// <param name= "strto