SMTP发送邮件程序问题,大侠帮帮我啊!!(50分)

  • 主题发起人 主题发起人 qyluo
  • 开始时间 开始时间
Q

qyluo

Unregistered / Unconfirmed
GUEST, unregistred user!
我用delphi的NMSMTP控件做了一个发送邮件的程序,他的各种需要的属性我都在程序中进行了设置
并且程序可以连接到163,263的SMTP服务器,但是我在发送的时候,他报如下的错误:
'553 You are not authorized to send mail as ....,authentication is required'
各位大侠帮帮忙!!
 
需要验证用户名和密码
 
没有啊,NMSMTP上面只有一个用户名的属性,我没有找到密码的属性啊!不知道该怎么办!?
 
老问题了,smtp要身份验证,看这个
unit UnitSmtpLogin;

interface

uses NMSMTP,classes,Sysutils;

type
EIdException = class(Exception);
TIdCardinalBytes = record
case Integer of
0: (
Byte1: Byte;
Byte2: Byte;
Byte3: Byte;
Byte4: Byte;);
1: (Whole: Cardinal);
end;

function login(smtp:TNMSMTP;user,password:string):boolean;


var
//MIME:
CodingTable: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
//UUE: CodingTable: string = '`!"#$%&amp;''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[/]^_';
//XXE: CodingTable: string = '+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';

//MIME:
FillChar: char = '=';
//UUE: CodingTable[1] or '~'
//XXE: CodingTable[1] or '~'

implementation

procedure EncodeUnit(const AIn1, AIn2, AIn3: Byte; var VOut: Cardinal);
var
LUnit: TIdCardinalBytes;
begin
LUnit.Byte1 := Ord(CodingTable[((AIn1 SHR 2) and 63) + 1]);
LUnit.Byte2 := Ord(CodingTable[(((AIn1 SHL 4) or (AIn2 SHR 4)) and 63) + 1]);
LUnit.Byte3 := Ord(CodingTable[(((AIn2 SHL 2) or (AIn3 SHR 6)) and 63) + 1]);
LUnit.Byte4 := Ord(CodingTable[(Ord(AIn3) and 63) + 1]);
VOut := LUnit.Whole;
end;

function Encode2(ASrcStream: TStream; const ABytes: integer = MaxInt): string;
var
LIn1, LIn2, LIn3: Byte;
LSize: integer;
LStartPos: integer;
LUnit: TIdCardinalBytes;
begin
//TODO: Make this more efficient. Profile it to test, but maybe make single calls to ReadBuffer
//then pull from memory
if (ABytes <> MaxInt) and ((ABytes mod 3) > 0) then begin
raise EIdException.Create('Uneven size in Encode.');
end;
Result := '';
LStartPos := ASrcStream.Position;
while (ASrcStream.Position < ASrcStream.Size) and (ASrcStream.Position - LStartPos < ABytes)
do begin
ASrcStream.ReadBuffer(LIn1, 1);
if ASrcStream.Position < ASrcStream.Size then begin
ASrcStream.ReadBuffer(LIn2, 1);
if ASrcStream.Position < ASrcStream.Size then begin
ASrcStream.ReadBuffer(LIn3, 1);
LSize := 3;
end else begin
LIn3 := 0;
LSize := 2;
end;
end else begin
LIn2 := 0;
LSize := 1;
end;
EncodeUnit(LIn1, LIn2, LIn3, LUnit.Whole);
Result := Result + Chr(LUnit.Byte1) + Chr(LUnit.Byte2) + Chr(LUnit.Byte3) + Chr(LUnit.Byte4);
if LSize < 3 then begin
Result[Length(Result)] := FillChar;
if LSize = 1 then begin
Result[Length(Result) - 1] := FillChar;
end;
end;
end;
end;

function Encode(const ASrc: string): string;
var
LSrcStream: TStringStream;
begin
LSrcStream := TStringStream.Create(ASrc); try
Result := Encode2(LSrcStream);
finally FreeAndNil(LSrcStream); end;
end;

function login(smtp:TNMSMTP;user,password:string):boolean;
const crlf = #13#10;
var
s:string;
begin
result:=false;
try
s:='auth LOGIN'+crlf;
smtp.SendBuffer(pchar(s),length(s));
s:=smtp.ReadLn;
if copy(s,1,3)<>'334' then exit; //Fail

s:=Encode(user)+crlf;
smtp.SendBuffer(pchar(s),length(s));
s:=copy(smtp.ReadLn,1,3);
if (s<>'334')and(s<>'235') then exit; //Fail

s:=Encode(password)+crlf;
smtp.SendBuffer(pchar(s),length(s));
s:=copy(smtp.ReadLn,1,3);
if (s<>'235') then exit; //Fail
result:=true;
except
end;
end;

end.
 
谢谢啦!!!!
 
可以拉,谢谢各位啦!!
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部