鱼C论坛

 找回密码
 立即注册
查看: 2969|回复: 4

一个群发软件的源码~~为什么单个邮件可以发~多个就出错~

[复制链接]
发表于 2012-4-4 10:41:23 | 显示全部楼层 |阅读模式
1鱼币
一个群发软件的源码~~为什么单个邮件可以发~多个就出错~求高手点拨下,当输入多个邮件时发送出错提示
报错Authentication Failed,只发送一个时就成功,源码如下:
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdMessage, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, IdMessageClient, IdSMTP, Menus;
type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Edit1: TEdit;
    Memo1: TMemo;
    Edit2: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Label8: TLabel;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Label9: TLabel;
    SaveDialog1: TSaveDialog;
    OpenDialog1: TOpenDialog;
    IdSMTP1: TIdSMTP;
    IdMessage1: TIdMessage;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
var filename:string;
begin
    OpenDialog1.Execute;
    filename:=OpenDialog1.FileName;
    Label9.Caption:=filename;
    TIdAttachment.Create(IdMessage1.MessageParts,filename);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
  if not OpenDialog1.Execute then Exit; //如果没有选择文件则退出
  ListBox1.Items.LoadFromFile(OpenDialog1.FileName);
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
  if ListBox1.Items.Count = 0 then exit;
  if SaveDialog1.Execute then //选择了保存文件
  ListBox1.Items.SaveToFile(SaveDialog1.FileName);
end;
procedure TForm1.N1Click(Sender: TObject);
var
  s: string;
begin
  s := InputBox('输入对话框', '请输入邮件地址:', '@');
  if (Length(s) > 5) and (Pos('@', s) < Pos('.', s)) then
    ListBox1.Items.Add(s);
end;
procedure TForm1.N2Click(Sender: TObject);
begin
     ListBox1.DeleteSelected;
end;
procedure TForm1.N3Click(Sender: TObject);
begin
ListBox1.Clear;
end;
procedure TForm1.Button6Click(Sender: TObject);
var
i,j :integer;
email:string;
begin
  IdSMTP1.AuthenticationType:=atlogin;
  IdSMTP1.Username:=trim(Edit5.Text);
  IdSMTP1.Password:=trim(Edit6.Text);
  IdSMTP1.Host:=trim(Edit4.Text);
  IdSMTP1.Connect;  //开始连接服务器
  label8.Visible :=true ;
  j:=ListBox1.Items.Count;
  for i:=0 to j-1 do
  begin
  label8.Caption :='共'+inttostr(j)+'封邮件正在发送第'+inttostr(i+1)+'封邮件';
  email:=trim(ListBox1.Items.Strings);
  IdMessage1.Body.Clear;
  IdMessage1.Subject:=Edit1.Text;
  IdMessage1.Body.Text := Memo1.Text;
  IdMessage1.Body.Assign(Memo1.Lines);
  IdMessage1.Recipients.EMailAddresses:=email;
  IdMessage1.From.Address:=Edit2.Text;
  idsmtp1.Authenticate;   //自动身份验证
  idSMTP1.Send(IdMessage1);  //发送邮件
  end;
   IdSMTP1.Disconnect;   //断开连接
   showmessage('发送完毕!');
   label8.Visible :=false ;
end;
end.

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
发表于 2012-4-4 23:40:03 | 显示全部楼层
感觉是你的那个邮件地址的获取是不是有问题,没有调试过!!只是凭经验说话
错了别怪我!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2012-4-5 12:28:23 | 显示全部楼层
兄弟你说对了~~解决了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-11-14 22:42:45 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-1-20 01:31:10 | 显示全部楼层
学习学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 02:11

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表