我是菜鸟,第一次来这里,分数也许不够散,请诸位原谅我。
我现在要做一个群发的东东,想用INDY的SMTP来做,群发的邮件有正文,比如,“亲爱的ANDY同学”,还有附件(比如资料等),哪位大虾可以提供些例城来看看?或者,DELPHI7里面哪里有SMTP的例程?
谢谢诸位。

解决方案 »

  1.   

    去这个网站http://www.marcocantu.com/md7/default.htm下 md7code.zip 第19章的SendList是例子程序。
      

  2.   

    www.51merit.com
     有多线群发的例子!而且我已经研究了3个多月了!
      

  3.   

    unit poperator;interface
    uses ppub, Windows, Messages, SysUtils, Controls, StdCtrls, Classes,
        Dialogs, IdMessage, IdBaseComponent, IdComponent, IdTCPConnection,
        DateUtils, StrUtils, IdTCPClient, IdMessageClient, IdSMTP, ComCtrls;type
        tmailThread = class(tthread)
        private
            FSendCOUNT: INTEGER;        smtpaddress: string; //smtp  µØÖ·
            smtpport: integer; //smtp ¶Ë¿Ú        userID: string;
            USERPWD: string;        SenderAddress: string; //·¢ÐÅÈËemail
            AcceptAddress: string; //ÊÕÐÅÈËemail        subject: string; //Ö÷Ìâ
            mesg: string; //ÕýÎÄ        IdSMTP: TIdSMTP;
            MailMessage: TIdMessage;
            Amail_parameter: Tmail_parameter;
            FStatusBar: TStatusBar;
            fmemo: tmemo;
            ferrmemo: tmemo;
            fmemo3: tmemo;
        protected
            procedure Execute; override;        function Set_MailMessage_DefaultParam(mail: string): Boolean; //ÉèÖÃĬÈϲÎÊý
            procedure SendMail();
            function LinkMailServer(): boolean;
            procedure terminate;
        public        FsendFlag: integer; // 1---Ò»¶ÏÒ»·¢  2--Á¬·¢
            bStop: boolean;
            constructor create(LStatusBar: TStatusBar; memo1: tmemo; lerrmemo: tmemo; lmemo3: tmemo);
        end;
        tDeletemailThread = class(tthread)
        private
        protected
            procedure Execute; override;
        end;var DeletemailThread: tDeletemailThread;
    implementationuses PDM;constructor tmailThread.create(LStatusBar: TStatusBar; memo1: tmemo; lerrmemo: tmemo; lmemo3: tmemo);
    begin
        FstatusBar := LStatusBar;
        Amail_parameter := Tmail_parameter.create;
        Amail_parameter.LOAD();
        MailMessage := TIdMessage.Create(nil);    IdSMTP := TIdSMTP.Create(nil);
        FsendFlag := 1;
        FSendCOUNT := 0;
        bStop := false;
        freeonterminate := true;
        fmemo := memo1;
        ferrmemo := lerrmemo;
        fmemo3 := lmemo3;
        inherited create(true);
    end;procedure tmailThread.terminate();
    begin
        IdSMTP.Free;
        inherited;
    end;
    function tmailThread.Set_MailMessage_DefaultParam(mail: string): Boolean; //ÉèÖÃĬÈϲÎÊý
    var i: integer;
    begin
        Randomize;    i := Random(smtpcount);    with IdSMTP do begin
            Host := ok_smtp[i]; // trim(Amail_parameter.Host); //SMTP·þÎñÆ÷µØÖ·
            Port := 25; // Amail_parameter.port; //SMTP·þÎñÆ÷¶Ë¿Ú
            UserId := ok_user[i]; //  Amail_parameter.UserId; //Óû§Õ˺Å
            password := ok_pwd[i]; // Amail_parameter.password; //Óû§ÃÜÂë
        end;    with MailMessage do begin
            Contenttype := 'text/html'; //?????????????
            Subject := Amail_parameter.Subject;
            body.Add(Amail_parameter.body); //ÓʼþÕýÎÄ
            from.Address := ok_from[i]; // Amail_parameter.from_Address; //·¢ÐÅÈ˵ØÖ·
            recipients.EMailAddresses := mail; //ÊÕÐÅÈ˵ØÖ·
        end;end;procedure tmailThread.Execute;
    begin
        SendMail();
    end;procedure tDeletemailThread.Execute;
    var s: string;
    begin
        while not TerMinated do
        begin
            dm.sq := 'update t_config set smain=' + #39 + cfg.smain + #39 + ',snum=' + #39 + cfg.snum + #39 + ',smail=' + #39 + cfg.smail + #39;
            dm.Exe_SQ;        sleep(10000);
        end;
    end;function tmailThread.LinkMailServer(): boolean;
    var a: integer;
    begin
        result := false;
        a := 0;
        if not IdSMTP.Connected then
        begin
            try
                IdSMTP.Connect(); //µ÷ÓÃconnectÁ¬½Ó·þÎñÆ÷
            except
                on E: Exception do
                begin
                    fmemo3.Lines.Add(IdSMTP.Host + 'Á¬½Ó´íÎó,' + E.Message);
                    exit;
                end;
            end;        if (IdSMTP.AuthSchemesSupported.IndexOf('login') <> -1) then
            begin
             //·&thorn;&Icirc;&ntilde;&AElig;÷&Ograve;&ordf;&Ccedil;ó&Ntilde;é&Ouml;¤
                IdSMTP.AuthenticationType := atLogin;
                try
                    if IdSMTP.Authenticate then //&Iacute;¨&sup1;&yacute;&Ntilde;é&Ouml;¤
                        a := a;            except
                    begin
                        IdSMTP.Disconnect; //&para;&Iuml;&iquest;&ordf;&Aacute;&not;&frac12;&Oacute;
                        exit;
                    end;
                end;
            end;
        end;
        result := true;
    end;procedure tmailThread.SendMail();
    var os, s: string; i: integer;
    begin
        s := dm.getNextMail();
        while s <> '' do
        begin
            Set_MailMessage_DefaultParam(s);
            if LinkMailServer() then
            begin
                try
                    os := s;
                    IdSMTP.Send(MailMessage);
                    INC(FSendCOUNT);
                    INC(SendCOUNT);
                    fmemo.Lines.Add(s + '·&cent;&Euml;&Iacute;&sup3;&Eacute;&sup1;&brvbar;...' + IdSMTP.Host);                FStatusBar.Panels.Items[3].Text := inttostr(SendCOUNT);
                    i := MinutesBetween(now(), Begin_tIME);
                    if i = 0 then
                        FStatusBar.Panels.Items[1].Text := inttostr(SendCOUNT)
                    else
                        FStatusBar.Panels.Items[1].Text := floattostr(SendCOUNT / i);
                    s := dm.getNextMail();
                except
                    on E: Exception do
                    begin
                        ferrmemo.Lines.Add(IdSMTP.Host + '&Aacute;&not;&frac12;&Oacute;&acute;í&Icirc;ó,' + E.Message);
                        s := dm.getNextMail();
                        fmemo3.Lines.Add(os + '------&Ouml;÷&para;&macr;&para;&Iuml;&iquest;&ordf;:' + IdSMTP.Host + ',&Ocirc;&Ugrave;&Aacute;&not;&frac12;&Oacute;...');
                        ferrmemo.Lines.Add(os);
                        idsmtp.Disconnect;
                    end;
                end;
            end
            else
            begin
                idsmtp.Disconnect;
            end;
            FStatusBar.Update;
          //  if (FsendFlag = 1) then idsmtp.Disconnect;
            if fmemo.Lines.Count > 2000 then fmemo.Clear;
            if ferrmemo.Lines.Count > 2000 then ferrmemo.Clear;
            if fmemo3.Lines.Count > 2000 then fmemo3.Clear;        if (s = '') then
            begin
                fmemo.Lines.Add('&Oacute;&ETH;&Ograve;&raquo;&cedil;&ouml;&Iuml;&szlig;&sup3;&Igrave;&Ograve;&Ntilde;&frac34;&shy;&Ccedil;&euml;&Ccedil;ó&sup2;&raquo;&micro;&frac12;&ETH;&Acirc;mail,&Ograve;&Ntilde;&frac34;&shy;&Ouml;&Otilde;&Ouml;&sup1;...');
                break;
            end;
            if TerMinated then
            begin
                fmemo.Lines.Add('&Oacute;&ETH;&Ograve;&raquo;&cedil;&ouml;&Iuml;&szlig;&sup3;&Igrave;&Ecirc;&Otilde;&micro;&frac12;TerMinated,&Ograve;&Ntilde;&frac34;&shy;&Ouml;&Otilde;&Ouml;&sup1;...');            break;
            end;
            if bStop then
            begin
                fmemo.Lines.Add('&Oacute;&ETH;&Ograve;&raquo;&cedil;&ouml;&Iuml;&szlig;&sup3;&Igrave;&Ecirc;&Otilde;&micro;&frac12;bStop&Iuml;&ucirc;&Iuml;&cent;,&Ograve;&Ntilde;&frac34;&shy;&Ouml;&Otilde;&Ouml;&sup1;...');
                break;
            end;    end;
    end;end.
      

  4.   

    Self.Status.Clear;
      Self.SMTP.Host := trim( Self.smtpHost.Text );
      Self.SMTP.Username := '[email protected]';
    //  Self.SMTP.AuthenticationType := atLogin;
      Self.SMTP.Password := '909990';
      Self.SMTP.Port := 25;
      Self.MailMessage.From.Address := trim( Self.MailFrom.Text );
      Self.MailMessage.Recipients.EMailAddresses := trim( Self.MailTo.Text );
      Self.MailMessage.Subject := trim( Self.Subject.Text );
      Self.MailMessage.Body.Text := Self.Body.Lines.Text;
      if FileExists( Self.Attach.Text ) then
        TIdAttachment.Create(Self.MailMessage.MessageParts,Attach.Text);
      try
          try
            SMTP.Connect(1000);
            SMTP.Send(MailMessage);
          except on E:Exception do
            Status.Lines.Insert(0, '错误: ' + E.Message);
          end;
      finally
          if SMTP.Connected then SMTP.Disconnect;
      end;
    错误:
    raise excption class EIdProtocalREplyError with message 'from <[email protected]>, message blocked, you are not autorized to send mail, authentication is required'如何是好?