CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  .NET Framework

请问为什么我用SmtpMail和MailMessage不能发邮件.

楼主honjo(斌)2004-05-04 20:42:35 在 .NET技术 / .NET Framework 提问

代码如下:  
  MailMessage   msgMail   =   new   MailMessage();    
  msgMail.To   =   honjo@sina.com;   //邮件接受者    
  msgMail.From   =   "hong102@21cn.com";    
  msgMail.Subject   =   "您的定单信息。";    
   
  msgMail.BodyFormat   =   MailFormat.Html;    
  string   strBody   =   "<html><body>Test   mail   messages!!!</body></html>"  
  msgMail.Body   =   strBody;  
  SmtpMail.SmtpServer   =   "localhost";  
  SmtpMail.Send(msgMail);    
   
  没有错误产生,但honjo@sina.com就是收不到邮件,  
  我用的是window2000server的IIS自带的smtp,服务已启,但会在\Inetpub\mailroot\Queue\下有邮件的文件,但就是不会向目标邮件发出去  
  妈的,搞了一天了,没搞出来,还望哪位有经验的赐教啊. 问题点数:0、回复次数:20Top

1 楼leogigi()回复于 2004-05-04 21:34:11 得分 0

SMTP的属性你设置了吗?  
  作为本地邮件服务器发送邮件你需要设置一些属性  
   
  首先,右击"默认SMTP虚拟服务器"  
  接着设置属性如下:    
    “访问”选项卡中设置访问权限。单击“身份验证”,选择“匿名访问”,表示任何用户都可以发送,其他两项不用选择;单击“连接控制”中的“连接”和“中段限制”中的“中断”,选中“仅以下列表除外”,表示可以许接入所有用户的访问。  
   
    “邮件”选项卡中设置邮件传输条件及限制,“限制邮件大小为”等四个选项可以使用默认值,无须更改;  
   
    “将未传递报告的副本发送到”可将发送不成功的邮件返回发件人,并且写明不成功的原因;“死信目录”设置没有发送成功的邮件被存放的位置。  
   
    “传输”选项中设置邮件传递时间,这里不用修改,使用默认值;“LDAP路由”选项用来指定服务器使用的目录服务器标识和属性,这里也不用启动它。  
   
    “安全”选项中设置使用发送服务器的有权用户,默认用户是“Administrators”,你可以单击“添加”添加使用用户。  
  Top

2 楼honjo(斌)回复于 2004-05-04 22:11:06 得分 0

还是发不出去啊,Top

3 楼fds2003(Hunter)回复于 2004-05-04 22:29:31 得分 0

msgMail.To="honjo@sina.com"是这么样的!Top

4 楼honjo(斌)回复于 2004-05-04 22:41:18 得分 0

楼上这位大哥,我改了也不行,文件还是在\Inetpub\mailroot\Queue\这个文件夹里,  
  没有发出去,真是气死人了,  
  请问,是不是用这个东东发mail要设置其它什么地方呢,  
  我看了很多其它人的示例,好像都是这样的,为什么唯独我的就不行呢?  
  郁闷啊...郁闷啊...郁闷啊...郁闷啊...Top

5 楼fds2003(Hunter)回复于 2004-05-04 22:42:05 得分 0

using   System;  
  using   System.Drawing;  
  using   System.Collections;  
  using   System.ComponentModel;  
  using   System.Windows.Forms;  
  using   System.Data;  
  using   System.Web.Mail;  
   
  namespace   SmtpClient  
  {  
  ///   <summary>  
  ///   Summary   description   for   Form1.  
  ///   </summary>  
  public   class   Form1   :   System.Windows.Forms.Form  
  {  
              private   System.Windows.Forms.Label   label1;  
              private   System.Windows.Forms.Label   label2;  
              private   System.Windows.Forms.Label   label3;  
              private   System.Windows.Forms.Label   label4;  
              private   System.Windows.Forms.TextBox   txtSmtpServer;  
              private   System.Windows.Forms.TextBox   txtRecipient;  
              private   System.Windows.Forms.TextBox   txtFrom;  
              private   System.Windows.Forms.TextBox   txtSubject;  
              private   System.Windows.Forms.Label   label5;  
              private   System.Windows.Forms.TextBox   txtMessage;  
              private   System.Windows.Forms.Label   label6;  
              private   System.Windows.Forms.TextBox   txtAttachment;  
              private   System.Windows.Forms.Button   button1;  
  ///   <summary>  
  ///   Required   designer   variable.  
  ///   </summary>  
  private   System.ComponentModel.Container   components   =   null;  
   
  public   Form1()  
  {  
  //  
  //   Required   for   Windows   Form   Designer   support  
  //  
  InitializeComponent();  
   
  //  
  //   TODO:   Add   any   constructor   code   after   InitializeComponent   call  
  //  
  }  
   
  ///   <summary>  
  ///   Clean   up   any   resources   being   used.  
  ///   </summary>  
  protected   override   void   Dispose(   bool   disposing   )  
  {  
  if(   disposing   )  
  {  
  if   (components   !=   null)    
  {  
  components.Dispose();  
  }  
  }  
  base.Dispose(   disposing   );  
  }  
   
  #region   Windows   Form   Designer   generated   code  
  ///   <summary>  
  ///   Required   method   for   Designer   support   -   do   not   modify  
  ///   the   contents   of   this   method   with   the   code   editor.  
  ///   </summary>  
  private   void   InitializeComponent()  
  {  
                    this.label1   =   new   System.Windows.Forms.Label();  
                    this.label2   =   new   System.Windows.Forms.Label();  
                    this.label3   =   new   System.Windows.Forms.Label();  
                    this.label4   =   new   System.Windows.Forms.Label();  
                    this.txtSmtpServer   =   new   System.Windows.Forms.TextBox();  
                    this.txtRecipient   =   new   System.Windows.Forms.TextBox();  
                    this.txtFrom   =   new   System.Windows.Forms.TextBox();  
                    this.txtSubject   =   new   System.Windows.Forms.TextBox();  
                    this.label5   =   new   System.Windows.Forms.Label();  
                    this.txtMessage   =   new   System.Windows.Forms.TextBox();  
                    this.label6   =   new   System.Windows.Forms.Label();  
                    this.txtAttachment   =   new   System.Windows.Forms.TextBox();  
                    this.button1   =   new   System.Windows.Forms.Button();  
                    this.SuspendLayout();  
                    //    
                    //   label1  
                    //    
                    this.label1.Location   =   new   System.Drawing.Point(16,   16);  
                    this.label1.Name   =   "label1";  
                    this.label1.TabIndex   =   0;  
                    this.label1.Text   =   "SMTP   Server:";  
                    //    
                    //   label2  
                    //    
                    this.label2.Location   =   new   System.Drawing.Point(16,   40);  
                    this.label2.Name   =   "label2";  
                    this.label2.TabIndex   =   1;  
                    this.label2.Text   =   "Recipient:";  
                    //    
                    //   label3  
                    //Top

6 楼fds2003(Hunter)回复于 2004-05-04 22:42:22 得分 0

this.label3.Location   =   new   System.Drawing.Point(16,   64);  
                    this.label3.Name   =   "label3";  
                    this.label3.TabIndex   =   2;  
                    this.label3.Text   =   "From:";  
                    //    
                    //   label4  
                    //    
                    this.label4.Location   =   new   System.Drawing.Point(16,   88);  
                    this.label4.Name   =   "label4";  
                    this.label4.TabIndex   =   3;  
                    this.label4.Text   =   "Subject:";  
                    //    
                    //   txtSmtpServer  
                    //    
                    this.txtSmtpServer.Location   =   new   System.Drawing.Point(104,   16);  
                    this.txtSmtpServer.Name   =   "txtSmtpServer";  
                    this.txtSmtpServer.Size   =   new   System.Drawing.Size(176,   20);  
                    this.txtSmtpServer.TabIndex   =   4;  
                    this.txtSmtpServer.Text   =   "";  
                    //    
                    //   txtRecipient  
                    //    
                    this.txtRecipient.Location   =   new   System.Drawing.Point(104,   40);  
                    this.txtRecipient.Name   =   "txtRecipient";  
                    this.txtRecipient.Size   =   new   System.Drawing.Size(176,   20);  
                    this.txtRecipient.TabIndex   =   5;  
                    this.txtRecipient.Text   =   "";  
                    //    
                    //   txtFrom  
                    //    
                    this.txtFrom.Location   =   new   System.Drawing.Point(104,   64);  
                    this.txtFrom.Name   =   "txtFrom";  
                    this.txtFrom.Size   =   new   System.Drawing.Size(176,   20);  
                    this.txtFrom.TabIndex   =   6;  
                    this.txtFrom.Text   =   "";  
                    //    
                    //   txtSubject  
                    //    
                    this.txtSubject.Location   =   new   System.Drawing.Point(104,   88);  
                    this.txtSubject.Name   =   "txtSubject";  
                    this.txtSubject.Size   =   new   System.Drawing.Size(176,   20);  
                    this.txtSubject.TabIndex   =   7;  
                    this.txtSubject.Text   =   "";  
                    //    
                    //   label5  
                    //    
                    this.label5.Location   =   new   System.Drawing.Point(16,   120);  
                    this.label5.Name   =   "label5";  
                    this.label5.TabIndex   =   8;  
                    this.label5.Text   =   "Message:";  
                    //    
                    //   txtMessage  
                    //    
                    this.txtMessage.Location   =   new   System.Drawing.Point(16,   136);  
                    this.txtMessage.Multiline   =   true;  
                    this.txtMessage.Name   =   "txtMessage";  
                    this.txtMessage.Size   =   new   System.Drawing.Size(264,   128);  
                    this.txtMessage.TabIndex   =   9;  
                    this.txtMessage.Text   =   "";  
                    //    
                    //   label6  
                    //    
                    this.label6.Location   =   new   System.Drawing.Point(16,   280);  
                    this.label6.Name   =   "label6";  
                    this.label6.Size   =   new   System.Drawing.Size(112,   23);  
                    this.label6.TabIndex   =   10;  
                    this.label6.Text   =   "Attachment   Location:";  
                    //    
                    //   txtAttachment  
                    //    
                    this.txtAttachment.Location   =   new   System.Drawing.Point(128,   280);  
                    this.txtAttachment.Name   =   "txtAttachment";  
                    this.txtAttachment.Size   =   new   System.Drawing.Size(152,   20);  
                    this.txtAttachment.TabIndex   =   11;  
                    this.txtAttachment.Text   =   "";  
                    //    
                    //   button1  
                    //    
                    this.button1.Location   =   new   System.Drawing.Point(200,   312);  
                    this.button1.Name   =   "button1";  
                    this.button1.Size   =   new   System.Drawing.Size(80,   32);  
                    this.button1.TabIndex   =   12;  
                    this.button1.Text   =   "Send";  
                    this.button1.Click   +=   new   System.EventHandler(this.button1_Click);  
                    //    
                    //   Form1  
                    //    
                    this.AutoScaleBaseSize   =   new   System.Drawing.Size(5,   13);  
                    this.ClientSize   =   new   System.Drawing.Size(292,   357);  
                    this.Controls.AddRange(new   System.Windows.Forms.Control[]   {  
                                                                                                                                              this.button1,  
                                                                                                                                              this.txtAttachment,  
                                                                                                                                              this.label6,  
                                                                                                                                              this.txtMessage,  
                                                                                                                                              this.label5,  
                                                                                                                                              this.txtSubject,  
                                                                                                                                              this.txtFrom,  
                                                                                                                                              this.txtRecipient,  
                                                                                                                                              this.txtSmtpServer,  
                                                                                                                                              this.label4,  
                                                                                                                                              this.label3,  
                                                                                                                                              this.label2,  
                                                                                                                                              this.label1});  
                    this.Name   =   "Form1";  
                    this.Text   =   "SMTP   Mail   Example";  
                    this.ResumeLayout(false);  
   
              }  
  #endregion  
   
  ///   <summary>  
  ///   The   main   entry   point   for   the   application.  
  ///   </summary>  
  [STAThread]  
  static   void   Main()    
  {  
  Application.Run(new   Form1());  
  }  
   
              private   void   button1_Click(object   sender,   System.EventArgs   e)  
              {  
                    //   Create   mail   message  
                    MailMessage   email   =   new   MailMessage();  
   
                    //   Set   message   parameters  
                    email.From   =   txtFrom.Text;  
                    email.To   =   txtRecipient.Text;  
                    email.Subject   =   txtSubject.Text;  
                    email.BodyFormat   =   System.Web.Mail.MailFormat.Text;  
                    email.Body   =   txtMessage.Text;  
   
                    //   Add   attachment  
                    email.Attachments.Add(new   MailAttachment(txtAttachment.Text,  
                          MailEncoding.Base64));  
   
                    //   Set   SMTP   server  
                    SmtpMail.SmtpServer   =   txtSmtpServer.Text;  
   
                    //   Now   send   message  
                    SmtpMail.Send(email);  
              }  
  }  
  }  
  Top

7 楼fds2003(Hunter)回复于 2004-05-04 22:43:01 得分 0

给个例子你看看!Top

8 楼honjo(斌)回复于 2004-05-04 22:51:54 得分 0

我是asp.net的webform一样吗?Top

9 楼AngelGavin(Gavin Lv)回复于 2004-06-09 08:06:52 得分 0

我发出去了  
  楼主还不行么?Top

10 楼tashanzhishi(小胖)回复于 2004-06-09 08:13:13 得分 0

搂住可以先用别的smtpserver试试,看看是不是你的smtpserver本身的问题Top

11 楼hfwang009(软件民工)回复于 2004-06-09 08:32:06 得分 0

同意,应该是楼主的smtpserver没有配置好Top

12 楼ITsoftware(ITsoftware)回复于 2004-07-07 16:34:01 得分 0

可能是瑞星的问题,关闭邮件发送监控就好了,这个问题曾经困扰了我好久Top

13 楼chhwang(浩浩*好想早日拥有闪耀的星星*★★★★★)回复于 2004-07-09 12:08:48 得分 0

有没有添加对System.Web.dll的引用啊Top

14 楼lofa(太阳闪闪)回复于 2004-07-14 13:40:01 得分 0

。net里面带的好像不支持Smtp服务器要求身份认证的情况,换OutLook的组件发送就能有这个功能。Top

15 楼cgmx(风向标)回复于 2004-07-14 14:59:55 得分 0

支持的.但要有权限.  
  就是邮件服务器(exchange等,或比如163的smtp服务器)要对你的服务器进行授权.准许你通过smtp  
  Top

16 楼spidertan(灭蚊刀)回复于 2004-07-15 14:54:34 得分 0

好像跟你的outlook配置也有关系,主要是邮件发送格式,sql   server中发送邮件时,一般要求我把outlook的邮件发送格式设置为“纯文本”,所以我想这个问题是不是也这样Top

17 楼xw123(熊熊大火把(熊材伟略))回复于 2004-07-15 15:31:43 得分 0

代吗(包括邮箱的设置   stmp   的设置)没有错误的话你就现卸载组件   再重新安装   或者换台机子试试!Top

18 楼zhzuo(秋枫)回复于 2004-07-31 19:40:37 得分 0

参考  
  http://blog.csdn.net/zhzuo/archive/2004/07/12/39459.aspxTop

19 楼ylh1223(LOVE ZJ)回复于 2004-08-03 16:11:07 得分 0

原因事smtp服务器需要身分验证,发送邮件之前添加如下代码:  
  email.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",   "1");  
  email.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","用户帐号");  
  email.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","用户密码");Top

20 楼goodcyg(JAVA&&Delphi)回复于 2004-08-11 16:49:28 得分 0

同意楼上的     你要用base64写个验证过程   要不你的邮件是发不出Top

相关问题

  • 不能发邮件!!!
  • 请问怎么用smtpmail发送邮件?
  • .net自带发送邮件类MailMessage!
  • ASP.NET如何用SmtpMail发送MIME邮件?
  • 为何不能发邮件?
  • IMAIL不能发邮件
  • exchange不能收发邮件
  • 不能发送邮件
  • 不能发邮件,WHY????????
  • 用SmtpMail发送邮件时怎么样知道邮件是否发送成功?

关键词

  • 邮件
  • msgmail
  • mailmessage

得分解答快速导航

  • 帖主:honjo

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo