我做了一个共享软件,如何在在用户使用时,把用户的信息发到我的email里?

解决方案 »

  1.   

    网上有许多发EMail的代码,复制到你的程序里。(Delphi6用NMSMTP控件,Delphi7用IndySMTP)。思路是这样:如果用户使用程序,就检测是否接入互联网。如果接入互联网,就发邮件。相关代码,我给你找一下。
      

  2.   

    呵呵~~不管他是在做什么软件了,接分要紧!下面是检测本机是否接入互联网的代码:uses WinINet;begin
      if InternetCheckConnection('http://www.csdn.net/', 1, 0) then
        //已接入互联网
      else
        //接入互联网;
    end;下面是一个用Delphi6的NMSMTP发邮件的文章,你自己整理一下:Delphi 6 发送电子邮件,我以前编过,就是用TNMSMTP控件发送成功的。不过很不幸,源程序在最近删了。因为程序在Delphi7里不能通用。网上的资料应该有用,可能除了一点没讲:发送邮件需要用到“身份验证”。在发送邮件时,需要把用户名、密码,变成BASE64编码,再发送过去验证。TNMSMTP控件没有提供身份验证的部分。如何加入身份验证?Use 里加入:IdCoder3to4;在NMSMTP的OnConnect事件中添加代码:var strUserName, strPassword: String;begin
      strUserName := Base64Encode('帐号'); //帐号字符串变成Base64编码
      strPassword := Base64Encode('密码'); //密码字符串变成Base64编码
      nmsmtp1.Transaction('EHLO') ;
      nmsmtp1.Transaction('AUTH LOGIN');   //身份验证
      nmsmtp1.Transaction(strUserName);
      nmsmtp1.Transaction(strPassword);
    end;至于其它部分,很容易在网上找到。有兴趣请在网上找到base64编码规则,弄清楚Base64Encode()函数是怎么编码的。如果找不到Base64Encode函数,我把当时自己编码的函数写给你,看看有没有用。function encodebase64(s:string):string;   //上面代码的函数名相应改过来。
    const
      Tb: String[64] =
      ('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');var
       i,a:integer;
       temp,temp1:string;
    begin
        temp:='';
        temp1:=s;
        if length(temp1) mod 3<>0 then temp1:=temp1+char(0);
        for i:=1 to length(temp1) do
          begin
             case (i-1) mod 3 of
              0:  begin
                     a:=ord(temp1[i]);
                     a:=a shr 2;
                     temp:=temp+tb[a+1];
                  end;
               1:  begin
                     a:=ord(temp1[i-1]) and 3;
                     a:=a shl 8+ ord(s[i]);
                     a:=a shr 4;
                     temp:=temp+tb[a+1];
                   end;
                2: begin
                     a:=ord(temp1[i-1]) and $F;
                     a:=a shl 8+ord(temp1[i]);
                     a:=a shr 6;
                     temp:=temp+tb[a+1];
                     a:=ord(temp1[i]);
                     a:=a and $3f;
                     temp:=temp+tb[a+1];
                   end;
                end;
          end;
          a:=length(s);
          if a mod 3=2 then
              begin
                  temp1:='';
                  for i:=1 to length(temp)-1 do temp1:=temp1+temp[i];
                  temp:=temp1;
              end;
          if (a>0) and (a mod 3<>0) then
             if  a mod 3 =1 then temp:=temp+'=='
              else temp:=temp+'=';
        result:=temp;
    end;呵呵!无意中找到了以前编的程序,这是一个简单得不能再简单的邮件发送程序。刚刚还用exe文件试发成功过。注意:下面程序只适用于DELPHI 6。程序基本写出了发邮件的要点,其它的你自己实践吧!用的是Delphi 6 自带的TNMSMTP控件。有很多人说用这个控件没办法发送邮件,其实可以的。unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Psock, NMsmtp, StdCtrls,IdCoder3to4;type
      TForm1 = class(TForm)
        NMSMTP1: TNMSMTP;
        Label1: TLabel;
        Edit1: TEdit;
        Label2: TLabel;
        Edit2: TEdit;
        Label3: TLabel;
        Edit3: TEdit;
        Label4: TLabel;
        Edit4: TEdit;
        Label5: TLabel;
        Edit5: TEdit;
        Edit6: TEdit;
        Label6: TLabel;
        Memo1: TMemo;
        Label7: TLabel;
        Label8: TLabel;
        Button1: TButton;
        ListBox1: TListBox;
        OpenDialog1: TOpenDialog;
        Button2: TButton;
        Button3: TButton;
        procedure Button1Click(Sender: TObject);
        procedure NMSMTP1Connect(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);   
    {发送邮件主要过程}
    begin
     NMSmtp1.Host:=Edit1.Text;  {SMTP服务器名,例如:'smtp.21cn.com'}
     NMSmtp1.UserID:=Edit2.Text;{用户名,例如:'jtchang'}
     NMSmtp1.PostMessage.FromAddress:=Edit4.Text; {发件人地址,例如:'[email protected]'}
     NMSmtp1.PostMessage.ToAddress.Clear;           {清除所有收件人地址}
     NMSmtp1.PostMessage.ToAddress.Add (Edit5.Text); {加一个收件人地址,例如:'[email protected]', 可以加多个收件人地址}
     NMSmtp1.PostMessage.Subject:=Edit6.Text;         {邮件主题}
     NMSmtp1.PostMessage.Body.Assign(Memo1.Lines);    {邮件正文,memo1里的文字}
     NMSmtp1.PostMessage.Attachments.AddStrings(ListBox1.Items); {邮件的附件。注意:为了防病毒某些邮箱不能发送*.exe、*.com、*.dll等文件。listbox1里字符串保存的是附件的文件名} //开始发送
     NMSmtp1.Connect;    {连接smtp服务器,当连接时NMSMTP1的OnConnect事件被激活。}
     NMSmtp1.SendMail;   {发送邮件}
     NMSmtp1.Disconnect;   {关闭连接} 
     application.MessageBox('邮件发送完成!','成功',0) ;
    end;procedure TForm1.NMSMTP1Connect(Sender: TObject);   {发邮件时身份验证}
    var
       strUserName, strPassword: String;
    begin
        strUserName := Base64Encode(edit2.Text);      {自已的邮箱帐号,例如 'jtchang',有些服务器可能要带域名,如'[email protected]'}
        strPassword := Base64Encode(edit3.Text);      {邮箱密码,我可不能告诉你。}
        nmsmtp1.Transaction('AUTH LOGIN');            {请求服务器身份验证}
        nmsmtp1.Transaction(strUserName);             {发送经过base64编码的帐号} 
        nmsmtp1.Transaction(strPassword);             {发送经过base64编码的密码}end;
    procedure TForm1.Button2Click(Sender: TObject);       {一次增加一个附件。仅加文件名,只要文件存在就行了。可以多个附件}
    begin
      if opendialog1.Execute then
        listbox1.Items.Add (opendialog1.FileName); 
    end;procedure TForm1.Button3Click(Sender: TObject);     {清除附件(清除文件名列表)}
    begin
      listbox1.Items.Clear ;
    end;end.