我是菜鸟,第一次来这里,分数也许不够散,请诸位原谅我。
我现在要做一个群发的东东,想用INDY的SMTP来做,群发的邮件有正文,比如,“亲爱的ANDY同学”,还有附件(比如资料等),哪位大虾可以提供些例城来看看?或者,DELPHI7里面哪里有SMTP的例程?
谢谢诸位。
我现在要做一个群发的东东,想用INDY的SMTP来做,群发的邮件有正文,比如,“亲爱的ANDY同学”,还有附件(比如资料等),哪位大虾可以提供些例城来看看?或者,DELPHI7里面哪里有SMTP的例程?
谢谢诸位。
解决方案 »
- 解释一下何为线程
- 询问动态库与读写卡相关问题
- Delphi程序中如何批量修改(*.txt)为(*.html)?谢谢!
- 请问如何在数据字典中实现全局字典与数据分片?如何实现查询?
- 我写了一个程序,在本机上运行没有问题,可在别的机子上出现."应用程序正常初始化(Oxc0000142)失败。请单击“确定”,终止应用程序",我的
- 请问怎样在delph中实现用xsd对xml的内容进行校验
- 本人想新开一个版块(程序人生),希望大家支持一下
- 如何运行一个外部程序,并且一直等待到它结束为止!
- 关于vod视频点播。
- 大批量数据导入Excel,如何加快速度
- 有终端接口协议,如何写接口程序
- 刚开始学,请教vcl入门得书籍!谢谢!
有多线群发的例子!而且我已经研究了3个多月了!
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
//·þÎñÆ÷ÒªÇóÑéÖ¤
IdSMTP.AuthenticationType := atLogin;
try
if IdSMTP.Authenticate then //ͨ¹ýÑéÖ¤
a := a; except
begin
IdSMTP.Disconnect; //¶Ï¿ªÁ¬½Ó
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 + '·¢Ëͳɹ¦...' + 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 + 'Á¬½Ó´íÎó,' + E.Message);
s := dm.getNextMail();
fmemo3.Lines.Add(os + '------Ö÷¶¯¶Ï¿ª:' + IdSMTP.Host + ',ÔÙÁ¬½Ó...');
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('ÓÐÒ»¸öÏß³ÌÒѾ­ÇëÇó²»µ½ÐÂmail,ÒѾ­ÖÕÖ¹...');
break;
end;
if TerMinated then
begin
fmemo.Lines.Add('ÓÐÒ»¸öÏß³ÌÊÕµ½TerMinated,ÒѾ­ÖÕÖ¹...'); break;
end;
if bStop then
begin
fmemo.Lines.Add('ÓÐÒ»¸öÏß³ÌÊÕµ½bStopÏûÏ¢,ÒѾ­ÖÕÖ¹...');
break;
end; end;
end;end.
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'如何是好?