用Indy发送邮件的问题(100分)

  • 主题发起人 主题发起人 hhi179
  • 开始时间 开始时间
H

hhi179

Unregistered / Unconfirmed
GUEST, unregistred user!
我用Indy作发送邮件程序,但对方收到的邮件全部都到垃圾邮件那里去了,如何使发送的邮件到收件箱里头,请各位大师指教。
 
下面是我用线程发邮件的过程,不会变成垃圾邮件,我试过.

procedure TMailThread.Execute;
var IdSMTP:TIdSMTP;
IdMsg:TIdmessage;
att:string;
Stop:boolean;
begin
{ Place thread code here }
FreeOnTerminate := True;

synchronize(LoadFromMain);
Idsmtp:=TIdsmtp.Create(nil);
IdMsg:=TIdmessage.Create(nil);

try

//构造邮件体
IdMsg.Subject := FSubject;
IdMsg.Body.Text := FContent;
IdMsg.From.Address := FMail;
IdMsg.Recipients.EMailAddresses := GetEmail(FToMail);
att:=FAttachment;
if FileExists(att) then TIdAttachment.Create(IdMsg.MessageParts, att);

//填充SMTP
IdSMTP.Host := GetHost;
IdSMTP.Port := 25;
IdSMTP.Username := GetUsername;
IdSMTP.Password := GetPS;

//连接到SMTP服务器
try
IdSMTP.Connect;
except
SendForm.Sending := false;
exit;
end;

//验证身分
if (IdSMTP.AuthSchemesSupported.IndexOf('LOGIN')<>-1) then
begin
IdSMTP.AuthenticationType :=atLogin;
try
if not IdSMTP.Authenticate then //未通过验证
begin
if IdSMTP.Connected then IdSMTP.Disconnect;
exit;
end;
except
if IdSMTP.Connected then IdSMTP.Disconnect;
exit;
end;
end;

//发送信件
try
IdSMTP.Send(IdMsg);
synchronize(DoSendLogTrue);
except
synchronize(DoSendLogFalse);
if IdSMTP.Connected then IdSMTP.Disconnect;
end;
if IdSMTP.Connected then IdSMTP.Disconnect;
finally
IdSMTP.Free;
IdMsg.Free;
end;
end;
 
我试过,这样也不会发到垃圾邮件箱里啊。

unit email_Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdMessageClient, IdSMTP, StdCtrls, IdMessage;

type
TForm1 = class(TForm)
IdSMTP1: TIdSMTP;
Button1: TButton;
IdMessage1: TIdMessage;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
Attachment_name:String;
begin
Attachment_name:='d:/attachment.rar';
IdSMTP1.AuthenticationType:=atLogin;
IdSMTP1.Host:='smtp.sohu.com';
IdSMTP1.Port:=25;
IdSMTP1.Username:='id';
IdSMTP1.Password:='pw';
IdMessage1.Body.add('测试中文4');
IdMessage1.From.Text:='abc@a.com';
IdMessage1.Recipients.EMailAddresses:='id@sina.com';
//IdMessage1.CCList.EMailAddresses := edtCC.Text;// {CC}
//IdMessage1.BccList.EMailAddresses:='weiliu@exelcs.com' //{BBC}
IdMessage1.Subject:='This is a test !';
if FileExists(Attachment_name) then TIdAttachment.Create(IdMessage1.MessageParts,Attachment_name);
try
IdSMTP1.Connect(-1);
IdSMTP1.Send(IdMessage1);
showmessage('OK');
except
showmessage('Error !');
end;
IdSMTP1.Disconnect;
end;

end.
 
多人接受答案了。
 
后退
顶部