请教如何在delphi中单击按钮后调用本地邮箱发邮件.

解决方案 »

  1.   

    uses
      shellApi;
    Shellexecute(0, nil, 'mailto:[email protected]', nil, nil, sw_ShowNormal);
      

  2.   

    是成功调出了Outlook Expree,能不能更方便点,就是不弹出这个,在程序里定义邮件标题和内容,当用户一点Botton时就自动发出去.
      

  3.   

    用indy Clients标签中的IdSMTP和indy Misc标签里的IdMessage,代码如下://-----问题是不知如何获取本机默认的邮件客户端的用户名去发这个邮件,
    //-----各位一起研究一下.unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, IdComponent, IdTCPConnection, IdTCPClient, IdMessageClient,
      IdSMTP, IdBaseComponent, IdMessage, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        MailMessage: TIdMessage;
        Mail: TIdSMTP;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      if Mail.Connected then Mail.Disconnect;
         Mail.Username:='mail_username';
         Mail.Password:='mail_password';
         Mail.Host:='220.181.12.15';
         Mail.Port:=25;
         Mail.AuthenticationType:=atLogin;
         MailMessage.Subject:='Hello Delphi';
         MailMessage.Body.Text:='Hello Delphi!!';
         MailMessage.From.Name:=''mail_username';
         MailMessage.From.Address:='[email protected]';
         MailMessage.ReplyTo.EMailAddresses:='[email protected]';
         MailMessage.Priority:=TidMessagePriority(1);
         MailMessage.Recipients.EMailAddresses:='[email protected]';
         MailMessage.From.Address:='[email protected]';
         try
           mail.Connect;
           mail.Authenticate;
           mail.Send(MailMessage);
         finally
           mail.Disconnect;
         end;
      end;end.
      

  4.   

    用delphi自己的idsmtp控件就可以实现,类似下面代码var
      mailaddress:TIdEMailAddressItem;
      i:integer;
    begin
      try
        if FIdSMTP.Connected then
          FIdSMTP.Disconnect;
        FIdMessage.charset:='GB2312_CHARSET';
        FIdMessage.ContentType:='text/html';
        FIdSMTP.Host :='邮件服务器';
        FIdSMTP.AuthenticationType := atLogin;
        FIdSMTP.Username := '用户名';
        FIdSMTP.Password := '密码';
        FIdSMTP.Connect;
        if FIdSMTP.Authenticate then
        begin
          //发信人
          FIdMessage.From.Address := FFromAddress;
          FIdMessage.From.Name := FFromUser;
          FIdMessage.Recipients.Clear;
          FIdMessage.ReplyTo.Clear;
          for i:=0 to FToAddress.Count-1 do
          begin
            mailaddress := FIdMessage.Recipients.Add;
            mailaddress.Address := FToAddress[i];
          end;
          mailaddress := FIdMessage.ReplyTo.Add;
          mailaddress.Address := '回复地址';
          //主题
          FIdMessage.subject:= FTopic;
          //信件内容
          with FIdMessage.Body do
          begin
            Clear;
            Add('<Html>');
            Add('<style type="text/css">');
            Add('<!--');
            Add('.STYLE7 {');
            Add(' font-size: 24px;');
            Add(' font-family: "宋体";');
            Add(' font-weight: bold;');
            Add('}');
            Add('.STYLE9 {color: #0066FF}');
            Add('.STYLE23 {font-weight: bold; font-size: 13pt; }');
            Add('.STYLE24 {color: #FF0000}');
            Add('.STYLE25 {');
            Add(' color: #0000FF;');
            Add(' font-weight: bold;');
            Add('} ');
            Add('.STYLE26 {');
            Add(' color: #993300;');
            Add(' font-weight: bold;');
            Add('}');
            Add('.STYLE27 {color: #993300}');
            Add('-->');
            Add('</style>');
            Add('<Body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0">');
            Add('<Font Size=3>');
            Add('<BR>');
            Add(' <span class="STYLE23">内容:'+FContent[0]+'</span><BR>');
             Add('</Font>');
            Add('</Body>');
            Add('</Html>');
          end;
          //发送
          try
            FIdSMTP.Send(FIdMessage);
          except
            Result := false;
          end;
        end else
        begin
          result := false;
        end;
      finally
        if FIdSMTP.Connected then
          FIdSMTP.Disconnect;
      end;
      

  5.   


    能不能用hide的方式打开Outlook Expree,然后,找到相应的Outlook Expree窗口内的句柄,把标题和内容发消息进去?
      

  6.   

    如果纯粹只是发一封邮件,用IDSMTP就好,调用OUTLOOK,现在很多人都不配置这个