我是c#的初学者,按照书上的实例写了个email小程序,每次在发送邮件的时候都会提示“未能访问到CDO.Message对象,我要怎么办?
解决方案 »
- C#2008中怎样用一个DataTable中字段的值更新另一个DataTable中字段的值
- 如何使用COM组件在64位Windows Server 2003 下正常运行?
- 用打开文件对话框能否打开一个文件夹?
- 求c#操作xml的程序
- 用VS2010连接SQLEXPRESS 2008时出现“未将对象引用设置到对象的实例。”,怎么解决
- 创建PPT文件 后面多了一个.DOC ???
- 我用C#写的桌面程序为什么一运行就报错“尝试读取或写入受保护的内存。这通常指示其他内存已损坏。"
- 郁闷,今天碰到了datatime问题
- c#调用java的webservice
- 没分的看过来!给前5个三角少的:)
- 唉这几天老做一些底层的东西,API又不熟,谁能提供一个读USB的类?要多少分开个价:)
- Datagrid 更新问题
{
try
{
MailMessage mail=new MailMessage();
mail.To=tabManageReviews_txtEmail.Text;
mail.From="[email protected]";
mail.Subject=tabManageReviews_cmboEmail.Text;
mail.BodyFormat=MailFormat.Html;
mail.Body=tabManageReviews_txtEmailText.Text; if(tabManageReviews_treeView1.SelectedNode.Text!="Attachments"&&tabManageReviews_treeView1.SelectedNode.Text!="Contracts")
{
MailAttachment ma=new MailAttachment("e:\\exe\\"+tabManageReviews_treeView1.SelectedNode.Parent.Text+"\\"+
tabManageReviews_treeView1.SelectedNode.Text+".doc");
mail.Attachments.Add(ma);
}
else
{
DialogResult DiRes;
DiRes=MessageBox.Show("You haven't selected a mail attachment"+
"Do You want to send mail anyway?","Send Without Attachment?",
MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation);
if(DiRes==DialogResult.No)
{
MessageBox.Show("Nothing was delivered.","Mail Canceled",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
}
DialogResult DiRes2;
DiRes2=MessageBox.Show("Please review your message."+
"Click 'ok to send or 'Cancel' to do just that. \n\n"
+tabManageReviews_txtEmailText.Text,"Send Message?",
MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
if(DiRes2==DialogResult.Cancel)
{
MessageBox.Show("Nothing was delivered.","Mail Canceled",
MessageBoxButtons.OK,MessageBoxIcon.Information);
tabManageReviews_treeView1.SelectedNode=tabManageReviews_treeView1.Nodes[0];
return;
}
SmtpMail.SmtpServer="ENTER YOUR MAILSERVER HERE!";
SmtpMail.Send(mail); MessageBox.Show("Mail has been sent","It's Official",MessageBoxButtons.OK,MessageBoxIcon.Information);
tabManageReviews_treeView1.SelectedNode=tabManageReviews_treeView1.Nodes[0];
}
catch(Exception ex)
{
MessageBox.Show("There was an erroe delivering your mail"+"The specific error message was \n\n:"+
ex.Message,"Mail Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
这是发送email的主代码了,望高手指教
http://www.cnblogs.com/NeoLee/archive/2005/03/28/127316.aspx不过
SmtpMail.SmtpServer="ENTER YOUR MAILSERVER HERE!";//呵呵,这样的代码再也不要出现了,发邮件总归是需要发件服务器,如果不知道SMTP服务器的名称如何发??
System.Web.Mail.MailMessage mail = new MailMessage();
mail.To="[email protected]";
mail.From="[email protected]";
mail.Priority = MailPriority.High;
mail.Subject = "It's a test!";
mail.Body = this.txt1.Text;
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",
"1");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",
"wacle");//your email user name
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",
"password");//your password here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing",2);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver","");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/languagecode",0x0804);
SmtpMail.Send(mail);
CDO是用于发送邮件的组件。mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing",2);1就是通过exchange来发。2就是通过SMTP服务器,3好像是用25的端口发。