日期:2014-05-20  浏览次数:20409 次

asp.net 2.0 邮件发送问题
MailMessage   em   =   new   MailMessage();
em.To   =   to;
em.From   =   from;
em.Subject   =   subject;
em.Body   =   message;

//Found   out   how   to   send   authenticated   email   via   System.Web.Mail   at   http://SystemWebMail.com   (fact   3.8)
if(this.UserName   !=   null   &&   this.Password   !=   null)
{
em.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate ",   "1 "); //basic   authentication
em.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendusername ",   this.UserName);   //set   your   username   here
em.Fields.Add( "http://schemas.microsoft.com/cdo/configuration/sendpassword ",   this.Password); //set   your   password   here

}

SmtpMail.SmtpServer   =   this.SmtpServer;
SmtpMail.Send(em);
                        }
我看了   hiForumsaspnet   和CNBlogsDottext的源代码,他们发送邮件中有那段url,请问这个安全么?为什么还要加这个东西呢?另外,他们写的程序太深奥了,上面是CNBlogsDottext的发送邮件的,UserName   和Password这两个东西到底在哪里赋值的?我到处找不到,希望看过这两个工程的朋友来指点一下,两个工程都是   是.net1.1上的,而且是很久以前的代码了,看过的朋友,如果知道这段代码,就可以联想到跟这个有关的上下文了

------解决方案--------------------
路过,学习
------解决方案--------------------
应该是安全的!其实不用去理会他,如果你不要if那段代码,也是可以执行成功的。
------解决方案--------------------
这是一个发邮件的类,你试试看吧。

using System;
using System.Net.Sockets;//用于处理网络连接
using System.IO; //用于处理附件的包
using System.Text;//用于处理文本编码
using System.Data;
using System.Net;

namespace Email
{
public class MailSend:TcpClient
{

/*SMTP服务器域名*/
private string strServer;
public string server
{
get
{
return strServer;
}
set
{
if(strServer!=value)
{
strServer=value;
}
}
}

/*SMTP服务器端口*/
private int strPort;
public int port
{
get
{
return strPort;
}
set
{
if(strPort!=value)
{
strPort=value;
}
}
}

/*用户名*/
private string strUse=null;
public String username
{
get
{
return strUse;
}
set
{
if(strUse!=value)
{
strUse=value;
}
}
}

/*密码*/
private string strPass=null;
public String password
{
get
{
return strPass;
}
set
{
if(strPass!=value)
{
strPass=value;
}
}
}

/*主题*/
private string strSub= " ";
public String subject
{
get
{
return strSub;
}
set
{
if(strSub!=value)
{
strSub=value;
}
}
}

/*文本内容*/
private string strBody= " ";
public String body
{
get
{
return strBody;
}
set
{
if(strBody!=value)
{
strBody=value;
}
}
}