CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

紧急求救:关于邮件发送!

楼主cul(恐龙++)2001-11-22 12:38:38 在 Delphi / VCL组件开发及应用 提问

用DELPHI怎么写邮件发送的?比如说我想点下一个按钮之后,发送一封邮件到某个地址,该怎么写代码?  
  我记得DELPHI带了例子的,怎么现在找不到了。谁给写段代码给我?或者告诉我DELPHI自带的例子在哪里(详细路径)也行啊?  
  马上给分!  
  快一点啊,各位大哥,我急等着用。 问题点数:100、回复次数:7Top

1 楼liang_z(千山一刀之忍者神龟)回复于 2001-11-22 12:49:41 得分 10

Demos\FastNet\Pop3Top

2 楼liang_z(千山一刀之忍者神龟)回复于 2001-11-22 12:50:26 得分 0

Demos\FastNet\SmtpTop

3 楼cul(恐龙++)回复于 2001-11-22 12:52:44 得分 0

谢了老千,一会儿回头来给你分。Top

4 楼leeky(雅痞·千年虫)回复于 2001-11-22 13:11:55 得分 5

放一个TLabel控件,设置它的鼠标形状,然后在它的Clik事件加入以下代码:  
    ShellExecute(Handle,   'open',   'http://go6.163.com/dica',   nil,   nil,   SW_SHOWNORMAL);  
  或:  
        ShellExecute(Handle,   'open',   'mailto:address@xxx.yyy',   nil,   nil,   SW_SHOWNORMAL);Top

5 楼cul(恐龙++)回复于 2001-11-22 13:33:59 得分 0

leeky(雅痞·千年虫) :  
  我是要自已完成发信的功能,不是调出OUTLOOK再发。Top

6 楼cobi(我是小新)回复于 2001-11-22 13:58:59 得分 85

你要用什么方式发,smtp   或   pop3  
   
  //这是我写的一个演示程序,    
  //窗体上有一个BUTTON控件,一个LABEL控件,一个NMSMTP控件    
  //带密码险证的邮件发送程序需要BASE64编码,DecodeBase64和   EncodeBase64    
  //为解码和编码函数    
  //在263、163和SOHU上都能发送成功    
  unit   Unit1;    
     
  interface    
     
  uses    
      Windows,   Messages,   SysUtils,   Classes,   Graphics,   Controls,   Forms,   Dialogs,    
      StdCtrls,   Psock,   NMsmtp,   ComCtrls;    
     
  type    
      TForm1   =   class(TForm)    
          NMSMTP1:   TNMSMTP;    
          Button1:   TButton;    
          Label1:   TLabel;    
          procedure   Button1Click(Sender:   TObject);    
          procedure   NMSMTP1Connect(Sender:   TObject);    
          procedure   NMSMTP1InvalidHost(var   Handled:   Boolean);    
          procedure   NMSMTP1ConnectionFailed(Sender:   TObject);    
          procedure   NMSMTP1Status(Sender:   TComponent;   Status:   String);    
          procedure   NMSMTP1SendStart(Sender:   TObject);    
          procedure   NMSMTP1Success(Sender:   TObject);    
      private    
          {   Private   declarations   }    
      public    
          {   Public   declarations   }    
      end;    
  //BaseTable为BASE64码表    
  const   BaseTable:string='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';    
     
  var    
      Form1:   TForm1;    
      AuthSucc:boolean;//   是否需要密码验证    
      function   DecodeBase64(Source:string):string;   //解码函数    
      function   FindInTable(CSource:char):integer;     //    
      function   EncodeBase64(Source:string):string;   //编码函数    
  implementation    
     
  {$R   *.DFM}    
  //    
  function   FindInTable(CSource:char):integer;    
  begin    
      result:=Pos(string(CSource),BaseTable)-1;    
  end;    
  ////    
  function   DecodeBase64(Source:string):string;    
  var    
      SrcLen,Times,i:integer;    
      x1,x2,x3,x4,xt:byte;    
  begin    
      result:='';    
      SrcLen:=Length(Source);    
      Times:=SrcLen   div   4;    
      for   i:=0   to   Times-1   do    
      begin    
          x1:=FindInTable(Source[1+i*4]);    
          x2:=FindInTable(Source[2+i*4]);    
          x3:=FindInTable(Source[3+i*4]);    
          x4:=FindInTable(Source[4+i*4]);    
          x1:=x1   shl   2;    
          xt:=x2   shr   4;    
          x1:=x1   or   xt;    
          x2:=x2   shl   4;    
          result:=result+chr(x1);    
          if   x3=   64   then   break;    
          xt:=x3   shr   2;    
          x2:=x2   or   xt;    
          x3:=x3   shl   6;    
          result:=result+chr(x2);    
          if   x4=64   then   break;    
          x3:=x3   or   x4;    
          result:=result+chr(x3);    
      end;    
  end;    
  /////    
  function   EncodeBase64(Source:string):string;    
  var    
      Times,LenSrc,i:integer;    
      x1,x2,x3,x4:char;    
      xt:byte;    
  begin    
      result:='';    
      LenSrc:=length(Source);    
      if   LenSrc   mod   3   =0   then   Times:=LenSrc   div   3    
      else   Times:=LenSrc   div   3   +   1;    
      for   i:=0   to   times-1   do    
      begin    
          if   LenSrc   >=   (3+i*3)   then    
          begin    
              x1:=BaseTable[(ord(Source[1+i*3])   shr   2)+1];    
              xt:=(ord(Source[1+i*3])   shl   4)   and   48;    
              xt:=xt   or   (ord(Source[2+i*3])   shr   4);    
              x2:=BaseTable[xt+1];    
              xt:=(Ord(Source[2+i*3])   shl   2)   and   60;    
              xt:=xt   or   (ord(Source[3+i*3])   shr   6);    
              x3:=BaseTable[xt+1];    
              xt:=(ord(Source[3+i*3])   and   63);    
              x4:=BaseTable[xt+1];    
          end    
          else   if   LenSrc>=(2+i*3)   then    
          begin    
              x1:=BaseTable[(ord(Source[1+i*3])   shr   2)+1];    
              xt:=(ord(Source[1+i*3])   shl   4)   and   48;    
              xt:=xt   or   (ord(Source[2+i*3])   shr   4);    
              x2:=BaseTable[xt+1];    
              xt:=(ord(Source[2+i*3])   shl   2)   and   60;    
              x3:=BaseTable[xt+1];    
              x4:='=';    
          end   else    
          begin    
              x1:=BaseTable[(ord(Source[1+i*3])   shr   2)+1];    
              xt:=(ord(Source[1+i*3])   shl   4)   and   48;    
              x2:=BaseTable[xt+1];    
              x3:='=';    
              x4:='=';    
          end;    
          result:=result+x1+x2+x3+x4;    
      end;    
  end;    
  //////////    
  procedure   TForm1.Button1Click(Sender:   TObject);    
  var   MailTo,MailBody:TStringList;    
  begin    
  Nmsmtp1.Host   :='smtp.sohu.com';    
  nmsmtp1.Port   :=25;    
  nmsmtp1.UserID   :='linbch';//发信人的用户名,必须是真实的    
  nmsmtp1.ReportLevel   :=1;    
  Nmsmtp1.TimeOut   :=10000;    
  nmsmtp1.Connect   ;         ///连接    
  if   AuthSucc=true   then   ////验证成功    
  begin    
      MailTo:=TStringList.Create;    
      MailTo.Add('cunmin1@163.net');    
      MailBody.Add('Hello   it   is   a   test');    
      nmsmtp1.PostMessage.FromAddress:='linbch@sohu.com';   //发信人的电子邮件地址    
      nmsmtp1.PostMessage.ToAddress   :=MailTo;    
      nmsmtp1.PostMessage.Body:=MailBody;    
      nmsmtp1.PostMessage.Subject   :='My   test';    
      Mailto.Clear   ;    
      //Mailto.Add('c:\a.txt');    
      //Mailto.Add('c:\b.txt');    
      //nmsmtp1.PostMessage.Attachments:=MailTo;   附件    
      MailTo.Free   ;    
      MailBody.Free;    
      nmsmtp1.SendMail;    
  end;    
  end;    
  procedure   TForm1.NMSMTP1Connect(Sender:   TObject);    
  begin    
  //////连接成功,下面用户认证过程    
      label1.caption:=nmsmtp1.Status;    
      if   nmsmtp1.ReplyNumber   =   250   then    
          label1.caption:=nmsmtp1.Transaction('auth   login');   //开始认证    
      if   nmsmtp1.ReplyNumber   =334   then   //返回值为334,让你输入用BASE64编码后的用户名    
          label1.caption:=nmsmtp1.Transaction('YWFhYWE=');//   用户名aaaaa    
      if   nmsmtp1.ReplyNumber   =334   then     //   返回值为334,让你输入用BASE64编码后的用户密码    
          label1.caption:=nmsmtp1.Transaction('MTIzNDU2');   //密码为123456    
      if   nmsmtp1.ReplyNumber   =235   then    
      begin    
          label1.caption:='successful';    
          AuthSucc:=true;    
      end;    
      //showmessage(label1.caption);    
  end;    
     
  procedure   TForm1.NMSMTP1InvalidHost(var   Handled:   Boolean);    
  begin    
      label1.caption   :='Invalid   Host';    
  end;    
     
  procedure   TForm1.NMSMTP1ConnectionFailed(Sender:   TObject);    
  begin    
  label1.caption   :='connect   failed';    
  end;    
     
  procedure   TForm1.NMSMTP1Status(Sender:   TComponent;   Status:   String);    
  begin    
      label1.caption   :=nmsmtp1.Status   ;    
  end;    
     
  procedure   TForm1.NMSMTP1SendStart(Sender:   TObject);    
  begin    
      label1.Caption   :='start   send';    
  end;    
     
  procedure   TForm1.NMSMTP1Success(Sender:   TObject);    
  begin    
      label1.Caption:='send   success!';    
  end;Top

7 楼w19995(w19995)回复于 2001-12-06 17:37:14 得分 0

喜欢Top

相关问题

  • 发送邮件
  • 发送邮件
  • 紧急有关发送邮件的问题,在线等...请大家帮帮忙
  • asp发送邮件
  • 邮件发送程序
  • 发送邮件的问题
  • 邮件发送的问题!
  • 邮件怎样发送呀
  • 用ASP.Net发送邮件
  • 邮件发送的问题???

关键词

  • 邮件
  • 控件
  • 代码
  • nmsmtp
  • 发送
  • tobject
  • nil
  • sender
  • procedure
  • handled

得分解答快速导航

  • 帖主:cul
  • liang_z
  • leeky
  • cobi

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

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