使用IDSMTP如何向www.163.com免费邮箱发邮件(100分)

  • 主题发起人 主题发起人 放飞
  • 开始时间 开始时间

放飞

Unregistered / Unconfirmed
GUEST, unregistred user!
我用isSMTP和idMessage作了一个发邮件的程序,在往我在www.163.com上发邮件时
总是提示 system is busy (登录成功,只是发不出去),后来将 idMessage 的noEncode
属性该成 True 后,邮件是发出去了,但是只是邮件正文被发送出去了,
其他的信息(发件人、主主题等信息)都没有了。请教哪位高手可以帮帮我,谢谢!
 
有个NMsmtp的。

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 = '`!"#$%&''()*+,-./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.
 
现在只能使用 idSMTP 了,否则改动太大了,
感谢 lcl_003 提供的程序
 
发附件是这个吧
TIdAttachment.Create(Idmessage.MessageParts, Filename)
其他不知道了:(
 
补充一点,我在局域网上使用 IMail 作的邮件服务器发送、接受一切正常!
 
我曾经看过一个帖子,就是讲的这个问题。
好像是163根据indy里的某个文件定义的一个变量屏蔽
了indy的使用,所以使用indy不能发附件(?).
你搜索一下以前的帖子,好像是屏蔽了indy的某个消息
变量定义就可以了。
 
没有找到
 
http://www.delphibbs.com/delphibbs/dispq.asp?LID=1298487
自己上去看看。
 
感谢 hq_pan 和 lcl003 的帮助,经过验证,确实是 163 网站的问题,问题已经解决
 
后退
顶部