用尽可用分-----发邮件的问题!
1,请问用ASP.NET怎样发邮件,我用CDO来做,老是有问题!
我的代码如下:
---------
MailMessage ms = new MailMessage();
ms.From = this.TextBoxTxt1.Text;
ms.To = this.TextBoxTxt2.Text;;
ms.Subject = this.TextBoxTxt3.Text;
ms.Body = this.ContentBoxTxt.Text;
ms.BodyFormat = MailFormat.Text;
ms.Priority = MailPriority.Normal;
try
{
SmtpMail.Send(ms);
}
catch(Exception _e)
{
}
---------
以上程序老是报:未能访问“CDO.Message”对象
我已经把cdosys.dll复制到bin目录下
并且已经using cdo
请大家帮忙看看是哪里设置不对么?
大家有什么好的发邮件的程序也照样给分!
---------
再问一下:
这样发送邮件的时候系统会检查邮件的正确性么(不管是发件人还是收件人的地址)?
如果不检查,那么自己怎样来判断邮件地址是否合法了,听说可以用正则表达式,但是怎么写呢?
谢谢!
问题多了一点,还希望大家帮忙:)
问题点数:85、回复次数:9Top
1 楼orcale()回复于 2005-05-14 14:58:14 得分 15
不用把cdo copy到bin目錄下.你隻要對dll進行引用後.會自己生成一個托管的cdo dll存放在dll下面。我就是用這個發郵件沒有發現問題
表達式參考:http://www.regexlib.com/REDetails.aspx?regexp_id=735Top
2 楼viyo(唯远)回复于 2005-05-14 15:00:11 得分 30
我以前用Jmail邮件代理实现过发邮件,很简单。
CDO.dll是.net程序集吗,是否应该先注册。
C#验证邮件的正则表达式的代码【转】
验证输入的正确性
public static bool isEmail(string inputEmail)
{
inputEmail = NulltoString(inputEmail);
string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex re = new Regex(strRegex);
if (re.IsMatch(inputEmail))
return (true);
else
return (false);
}
验证邮件地址的正确性:
string[] host = (address.Split(@));
string hostname = host[1];
IPHostEntry IPhst = Dns.Resolve(hostname);
IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
Socket s= new Socket(endPt.AddressFamily, SocketType.Stream,ProtocolType.Tcp);
s.Connect(endPt);
//Attempting to connect
if(!Check_Response(s, SMTPResponse.CONNECT_SUCCESS))
{
s.Close();
return false;
}
//HELO server
Senddata(s, string.Format("HELO {0}\r\n", Dns.GetHostName() ));
if(!Check_Response(s, SMTPResponse.GENERIC_SUCCESS))
{
s.Close();
return false;
}
//Identify yourself
//Servers may resolve your domain and check whether you are listed in BlackLists etc.
Senddata(s, string.Format("MAIL From: {0}\r\n","testexample@deepak.portland.co.uk"));
if(!Check_Response(s, SMTPResponse.GENERIC_SUCCESS))
{
s.Close();
return false;
}
//Attempt Delivery (I can use VRFY, but most SMTP servers only disable it for security reasons)
Senddata(s, address);
if(!Check_Response(s, SMTPResponse.GENERIC_SUCCESS))
{
s.Close();
return false;
}
return (true);
Top
3 楼kandyasp(博客收集 http://www.1638988.cn)回复于 2005-05-14 15:03:50 得分 20
MailMessage mail = new MailMessage();
mail.To = "me@mycompany.com";
mail.From = "you@yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "Some text goes here";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret"); //set your password here
SmtpMail.SmtpServer = "mail.mycompany.com"; //your real server goes here
SmtpMail.Send( mail );
Top
4 楼Kshape(C/C++初学者~~~~)回复于 2005-05-14 16:46:06 得分 0
orcale()
--------
我是进行了引用的!
是不是在“解决方案”那里点“引用”,然后“添加引用”?
它也生成了一个DLL,Interop.CDO.DLLTop
5 楼Kshape(C/C++初学者~~~~)回复于 2005-05-14 17:06:52 得分 0
NulltoString(
怎么说找不到???Top
6 楼Kshape(C/C++初学者~~~~)回复于 2005-05-14 19:52:03 得分 0
现在正则表达式可以了
但是发送邮件依然有问题
大家帮忙啊Top
7 楼mba9001(两年不见,csdn变肥了)回复于 2005-05-14 20:53:55 得分 20
你的mail服务器是哪的,要不要验证?Top
8 楼Kshape(C/C++初学者~~~~)回复于 2005-05-14 22:05:13 得分 0
还要怎样配置那个啊?
Top
9 楼Kshape(C/C++初学者~~~~)回复于 2005-05-15 11:16:49 得分 0
大家给个发邮件的解决方案好么?Top




