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
请大家帮忙看看是哪里设置不对么?
大家有什么好的发邮件的程序也照样给分!
---------
再问一下:
这样发送邮件的时候系统会检查邮件的正确性么(不管是发件人还是收件人的地址)?
如果不检查,那么自己怎样来判断邮件地址是否合法了,听说可以用正则表达式,但是怎么写呢?
谢谢!
问题多了一点,还希望大家帮忙:)
我的代码如下:
---------
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
请大家帮忙看看是哪里设置不对么?
大家有什么好的发邮件的程序也照样给分!
---------
再问一下:
这样发送邮件的时候系统会检查邮件的正确性么(不管是发件人还是收件人的地址)?
如果不检查,那么自己怎样来判断邮件地址是否合法了,听说可以用正则表达式,但是怎么写呢?
谢谢!
问题多了一点,还希望大家帮忙:)
表達式參考:http://www.regexlib.com/REDetails.aspx?regexp_id=735
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","[email protected]"));
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);
mail.To = "[email protected]";
mail.From = "[email protected]";
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 );
--------
我是进行了引用的!
是不是在“解决方案”那里点“引用”,然后“添加引用”?
它也生成了一个DLL,Interop.CDO.DLL
怎么说找不到???