哪位兄弟肯帮帮忙,
发个邮件收发的源码给我,
要支持验证模式的
在这里先谢谢各位了
发个邮件收发的源码给我,
要支持验证模式的
在这里先谢谢各位了
解决方案 »
- 向大家推荐一个用DELPHI6开发的简单实用的远程控制软件: 学友远程助手
- 懂VB和Delphi的高手进
- asp问题
- delphi的excel输出不在同一个表中的问题,请赐教!谢谢
- 文件打开的问题
- 串口问题
- 现在在新单位团队开发,不象以前那样单干,但接手同事代码不明白他思路,看不明白,怎么办
- 中专生怎么啦?我自认一点都不比大学生差,可投了几十份简历,都石沉大海!
- 'select a,sum(f) from c group by a where e>=:e and e<=:e1'这句话错在哪?
- <Windows高级编程>后面的设备I/O太难学了,请问各位高手有何心得,连例子也很少
- 具有挑战性的题目~~~你不想试试吗~~~谁第一个成功额外加分~~~~当然参与者均有分可得
- 生僻的dxNavBar控件应用!!!
procedure Tform1.SendAlarmEmail;
begin
if SMTPAuthority then //SMTPAuthority 是 表示这个SMTP服务器是否需要认证的boolean
SMTP.AuthenticationType := atLogin
else SMTP.AuthenticationType := atNone;
SMTP.UserID := [email protected];//帐户
SMTP.Password := **********;//密码
{General setup}
SMTP.Host := SMTP.263.net;
SMTP.Port := 25;
try
SMTP.Connect;
except
Showmessage(‘连接SMTP服务器失败!‘);
Exit;
end;
try
with IdMsgSend do
begin
body.Clear;
Body.Add(‘hello world‘);//内容
From.Text := ‘[email protected]‘;
Recipients.EMailAddresses :=‘[email protected]‘//收件人
Subject:=‘老友,哈喽‘//主题
end;
SMTP.Send(IdMsgSend);
finally
SMTP.Disconnect;
end;
end;
with IdMsgSend do
begin
Body.Add(FEmailText); //邮件正文
From.Address := Trim(FEMail); //发件人地址
Recipients.EMailAddresses := Trim(FAimEmail); //收件人地址
Subject := FSubject; //邮件主题
end;
//send mail
with IdSMTP do
begin
UserId := FUserName;
Password := FPassword;
Host := FEMIP; // 将Host赋值为目的地,这就是特快专递与普通邮件的区别
Port := FEMPort; // smtp服务默认的端口为25
end; with IdSMTP do
begin
try
if not Connected then //连接到服务器
Connect;
Send(IdMsgSend); //发送刚才创建的邮件
except
//Disconnect; //断开服务器连接
end;
end;
//带密码险证的邮件发送程序需要BASE64编码,DecodeBase64和 EncodeBase64
//为解码和编码函数
//在263、163和SOHU上都能发送成功
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Psock, NMsmtp, ComCtrls;type
TForm1 = class(TForm)
NMSMTP1: TNMSMTP;
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure NMSMTP1Connect(Sender: TObject);
procedure NMSMTP1InvalidHost(var Handled: Boolean);
procedure NMSMTP1ConnectionFailed(Sender: TObject);
procedure NMSMTP1Status(Sender: TComponent; Status: String);
procedure NMSMTP1SendStart(Sender: TObject);
procedure NMSMTP1Success(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
//BaseTable为BASE64码表
const BaseTable:string='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';var
Form1: TForm1;
AuthSucc:boolean;// 是否需要密码验证
function DecodeBase64(Source:string):string; //解码函数
function FindInTable(CSource:char):integer; //
function EncodeBase64(Source:string):string; //编码函数
implementation{$R *.DFM}
//
function FindInTable(CSource:char):integer;
begin
result:=Pos(string(CSource),BaseTable)-1;
end;
////
function DecodeBase64(Source:string):string;
var
SrcLen,Times,i:integer;
x1,x2,x3,x4,xt:byte;
begin
result:='';
SrcLen:=Length(Source);
Times:=SrcLen div 4;
for i:=0 to Times-1 do
begin
x1:=FindInTable(Source[1+i*4]);
x2:=FindInTable(Source[2+i*4]);
x3:=FindInTable(Source[3+i*4]);
x4:=FindInTable(Source[4+i*4]);
x1:=x1 shl 2;
xt:=x2 shr 4;
x1:=x1 or xt;
x2:=x2 shl 4;
result:=result+chr(x1);
if x3= 64 then break;
xt:=x3 shr 2;
x2:=x2 or xt;
x3:=x3 shl 6;
result:=result+chr(x2);
if x4=64 then break;
x3:=x3 or x4;
result:=result+chr(x3);
end;
end;
/////
function EncodeBase64(Source:string):string;
var
Times,LenSrc,i:integer;
x1,x2,x3,x4:char;
xt:byte;
begin
result:='';
LenSrc:=length(Source);
if LenSrc mod 3 =0 then Times:=LenSrc div 3
else Times:=LenSrc div 3 + 1;
for i:=0 to times-1 do
begin
if LenSrc >= (3+i*3) then
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
xt:=xt or (ord(Source[2+i*3]) shr 4);
x2:=BaseTable[xt+1];
xt:=(Ord(Source[2+i*3]) shl 2) and 60;
xt:=xt or (ord(Source[3+i*3]) shr 6);
x3:=BaseTable[xt+1];
xt:=(ord(Source[3+i*3]) and 63);
x4:=BaseTable[xt+1];
end
else if LenSrc>=(2+i*3) then
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
xt:=xt or (ord(Source[2+i*3]) shr 4);
x2:=BaseTable[xt+1];
xt:=(ord(Source[2+i*3]) shl 2) and 60;
x3:=BaseTable[xt+1];
x4:='=';
end else
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
x2:=BaseTable[xt+1];
x3:='=';
x4:='=';
end;
result:=result+x1+x2+x3+x4;
end;
end;
//////////
procedure TForm1.Button1Click(Sender: TObject);
var MailTo,MailBody:TStringList;
begin
Nmsmtp1.Host :='smtp.sohu.com';
nmsmtp1.Port :=25;
nmsmtp1.UserID :='linbch';//发信人的用户名,必须是真实的
nmsmtp1.ReportLevel :=1;
Nmsmtp1.TimeOut :=10000;
nmsmtp1.Connect ; ///连接
if AuthSucc=true then ////验证成功
begin
MailTo:=TStringList.Create;
MailTo.Add('[email protected]');
MailBody.Add('Hello it is a test');
nmsmtp1.PostMessage.FromAddress:='[email protected]'; //发信人的电子邮件地址
nmsmtp1.PostMessage.ToAddress :=MailTo;
nmsmtp1.PostMessage.Body:=MailBody;
nmsmtp1.PostMessage.Subject :='My test';
Mailto.Clear ;
//Mailto.Add('c:\a.txt');
//Mailto.Add('c:\b.txt');
//nmsmtp1.PostMessage.Attachments:=MailTo; 附件
MailTo.Free ;
MailBody.Free;
nmsmtp1.SendMail;
end;
end;
procedure TForm1.NMSMTP1Connect(Sender: TObject);
begin
//////连接成功,下面用户认证过程
label1.caption:=nmsmtp1.Status;
if nmsmtp1.ReplyNumber = 250 then
label1.caption:=nmsmtp1.Transaction('auth login'); //开始认证
if nmsmtp1.ReplyNumber =334 then //返回值为334,让你输入用BASE64编码后的用户名
label1.caption:=nmsmtp1.Transaction('YWFhYWE=');// 用户名aaaaa
if nmsmtp1.ReplyNumber =334 then // 返回值为334,让你输入用BASE64编码后的用户密码
label1.caption:=nmsmtp1.Transaction('MTIzNDU2'); //密码为123456
if nmsmtp1.ReplyNumber =235 then
begin
label1.caption:='successful';
AuthSucc:=true;
end;
//showmessage(label1.caption);
end;procedure TForm1.NMSMTP1InvalidHost(var Handled: Boolean);
begin
label1.caption :='Invalid Host';
end;procedure TForm1.NMSMTP1ConnectionFailed(Sender: TObject);
begin
label1.caption :='connect failed';
end;procedure TForm1.NMSMTP1Status(Sender: TComponent; Status: String);
begin
label1.caption :=nmsmtp1.Status ;
end;procedure TForm1.NMSMTP1SendStart(Sender: TObject);
begin
label1.Caption :='start send';
end;procedure TForm1.NMSMTP1Success(Sender: TObject);
begin
label1.Caption:='send success!';
end;end.
Function QuotedPrintableEncode(mSource: String): String;
Var
I, J: Integer;
Begin
Result := '';
J := 0;
For I := 1 To Length(mSource) Do Begin
If mSource[I] In [#32..#127, #13, #10] - ['='] Then Begin
Result := Result + mSource[I];
Inc(J);
End Else Begin
Result := Result + '=' + IntToHex(Ord(mSource[I]), 2);
Inc(J, 3);
End;
If mSource[I] In [#13, #10] Then J := 0;
If J >= 70 Then Begin
Result := Result + #13#10;
J := 0;
End;
End;
End; { QuotedPrintableEncode }Function QuotedPrintableDecode(mCode: String): String;
Var
I, J, L: Integer;
Begin
Result := '';
J := 0;
mCode := AdjustLineBreaks(mCode);
L := Length(mCode);
I := 1;
While I <= L Do Begin
If mCode[I] = '=' Then Begin
Result := Result + Chr(StrToIntDef('$' + Copy(mCode, I + 1, 2), 0));
Inc(J, 3);
Inc(I, 3);
End Else If mCode[I] In [#13, #10] Then Begin
If J < 70 Then Result := Result + mCode[I];
If mCode[I] = #10 Then J := 0;
Inc(I);
End Else Begin
Result := Result + mCode[I];
Inc(J);
Inc(I);
End;
End;
End; { QuotedPrintableDecode }
Function Base64Encode(mSource: String; mAddLine: Boolean = True): String;
Var
I, J: Integer;
S: String;
Begin
Result := '';
J := 0;
For I := 0 To Length(mSource) Div 3 - 1 Do Begin
S := Copy(mSource, I * 3 + 1, 3);
Result := Result + cBase64[Ord(S[1]) Shr 2 + 1];
Result := Result + cBase64[((Ord(S[1]) And $03) Shl 4) + (Ord(S[2]) Shr 4) + 1];
Result := Result + cBase64[((Ord(S[2]) And $0F) Shl 2) + (Ord(S[3]) Shr 6) + 1];
Result := Result + cBase64[Ord(S[3]) And $3F + 1];
If mAddLine Then Begin
Inc(J, 4);
If J >= 76 Then Begin
Result := Result + #13#10;
J := 0;
End;
End;
End;
I := Length(mSource) Div 3;
S := Copy(mSource, I * 3 + 1, 3);
Case Length(S) Of
1: Begin
Result := Result + cBase64[Ord(S[1]) Shr 2 + 1];
Result := Result + cBase64[(Ord(S[1]) And $03) Shl 4 + 1];
Result := Result + cBase64[65];
Result := Result + cBase64[65];
End;
2: Begin
Result := Result + cBase64[Ord(S[1]) Shr 2 + 1];
Result := Result + cBase64[((Ord(S[1]) And $03) Shl 4) + (Ord(S[2]) Shr 4) + 1];
Result := Result + cBase64[(Ord(S[2]) And $0F) Shl 2 + 1];
Result := Result + cBase64[65];
End;
End;
End; { Base64Encode }Function Base64Decode(mCode: String): String;
Var
I, L: Integer;
S: String;
Begin
Result := '';
L := Length(mCode);
I := 1;
While I <= L Do Begin
If Pos(mCode[I], cBase64) > 0 Then Begin
S := Copy(mCode, I, 4);
If (Length(S) = 4) Then Begin
Result := Result + Chr((Pos(S[1], cBase64) - 1) Shl 2 +
(Pos(S[2], cBase64) - 1) Shr 4);
If S[3] <> cBase64[65] Then Begin
Result := Result + Chr(((Pos(S[2], cBase64) - 1) And $0F) Shl 4 +
(Pos(S[3], cBase64) - 1) Shr 2);
If S[4] <> cBase64[65] Then
Result := Result + Chr(((Pos(S[3], cBase64) - 1) And $03) Shl 6 +
(Pos(S[4], cBase64) - 1));
End;
End;
Inc(I, 4);
End Else Inc(I);
End;
End; { Base64Decode }Function GetTitle(Const Value: String): String;
Var
iPos: integer;
Begin
Result := Value;
If Copy(Value, 1, 2) <> '=?' Then
Begin
Result := Value;
exit;
End;
//'?B?'前面的都要去掉
iPos := Pos('?B?', Value);
If iPos = 0 Then
Begin
iPos := Pos('?Q?', Value);
If iPos = 0 Then
Begin
Result := Value;
exit;
End;
Inc(iPos, 3);
//最后的'?='也要去掉
Result := Copy(Value, iPos, Length(Value) - iPos - 1);
Result := QuotedPrintableDecode(Result);
End
Else
Begin
Inc(iPos, 3);
//最后的'?='也要去掉
Result := Copy(Value, iPos, Length(Value) - iPos - 1);
Result := Base64Decode(Result);
End;End;
假如body也是mime编码的怎么判断也解码?请有空的时候回答一下,非常感谢