我搜索了以往的帖子,都不成功。
谁能给出完整答案?给100分。
6 个解决方案
#1
procedure TForm1.Button1Click(Sender: TObject);
begin
NMSMTP1.Host := 'mail.host.com';
NMSMTP1.UserID := 'Username';
NMSMTP1.Connect;
NMSMTP1.PostMessage.FromAddress := 'webmaster@swissdelphicenter.ch';
NMSMTP1.PostMessage.ToAddress.Text := 'user@host.com';
NMSMTP1.PostMessage.ToCarbonCopy.Text := 'AnotherUser@host.com';
NMSMTP1.PostMessage.ToBlindCarbonCopy.Text := 'AnotherUser@host.com';
NMSMTP1.PostMessage.Body.Text := 'This is the message';
NMSMTP1.PostMessage.Attachments.Text := 'c:\File.txt';
NMSMTP1.PostMessage.Subject := 'Mail subject';
NMSMTP1.SendMail;
ShowMessage('Mail sent !');
NMSMTP1.Disconnect;
end;
begin
NMSMTP1.Host := 'mail.host.com';
NMSMTP1.UserID := 'Username';
NMSMTP1.Connect;
NMSMTP1.PostMessage.FromAddress := 'webmaster@swissdelphicenter.ch';
NMSMTP1.PostMessage.ToAddress.Text := 'user@host.com';
NMSMTP1.PostMessage.ToCarbonCopy.Text := 'AnotherUser@host.com';
NMSMTP1.PostMessage.ToBlindCarbonCopy.Text := 'AnotherUser@host.com';
NMSMTP1.PostMessage.Body.Text := 'This is the message';
NMSMTP1.PostMessage.Attachments.Text := 'c:\File.txt';
NMSMTP1.PostMessage.Subject := 'Mail subject';
NMSMTP1.SendMail;
ShowMessage('Mail sent !');
NMSMTP1.Disconnect;
end;
#2
系统显示‘用户未验证’。
是不是与SMTP服务器有关?
自己怎样设置自己的SMTP服务器?
是不是与SMTP服务器有关?
自己怎样设置自己的SMTP服务器?
#3
说明服务器需要用户验证
设置auth属性、发送者信箱、密码,且发送者须是该服务器的用户
设置auth属性、发送者信箱、密码,且发送者须是该服务器的用户
#4
添加NMSMTP1的OnConnect事件代码
procedure TForm1.NMSMTP1Connect(Sender: TObject);
begin
NMSMTP1.Transaction('AUTH LOGIN');
NMSMTP1.Transaction(EncodeString(用户名));
NMSMTP1.Transaction(EncodeString(密码));
end;
EncodeString是将字符串进行Base64编码
函数如下:
{对参数Decoded字符串进行Base64编码,返回编码后的字符串}
function EncodeString(Decoded:string):String;
var
mmTemp,mmDecoded:TMemoryStream;
strTemp:TStrings;
begin
mmTemp := TMemoryStream.Create;
mmDecoded:=TMemoryStream.Create;
strTemp:=TStringList.Create;
strTemp.Add(Decoded);
strTemp.SaveToStream(mmTemp);
mmTemp.Position := 0;
{剔除mmTemp从strTemp中带来的字符#13#10}
mmDecoded.CopyFrom(mmTemp,mmTemp.Size-2);
{对mmDecoded进行Base64编码,由mmTemp返回编码后的结果}
EncodeBASE64(mmTemp,mmDecoded);
{获得Base64编码后的字符串}
mmTemp.Position:=0;
strTemp.LoadFromStream(mmTemp);
{返回结果必须从strTemp[0]中获得,如果使用strTemp.Text会
带来不必要的字符#13#10}
Result:=strTemp[0];
end;
function EncodeBASE64(Encoded: TMemoryStream ; Decoded: TMemoryStream): Integer;
const
_Code64: String[64] =
('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');
var
I: LongInt;
B: array[0..2279] of Byte;
J, K, L, M, Quads: Integer;
Stream: string[76];
EncLine: String;
begin
Encoded.Clear;
Stream := ' ';
Quads := 0;
{为提高效率,每2280字节流为一组进行编码}
J := Decoded.Size div 2280;
Decoded.Position := 0;
{对前J*2280个字节流进行编码}
for I := 1 to J do
begin
Decoded.Read(B, 2280);
for M := 0 to 39 do begin
for K := 0 to 18 do begin
L:= 57*M + 3*K;
Stream[Quads+1] := _Code64[(B[L] div 4)+1];
Stream[Quads+2] := _Code64[(B[L] mod 4)*16 + (B[L+1] div 16)+1];
Stream[Quads+3] := _Code64[(B[L+1] mod 16)*4 + (B[L+2] div 64)+1];
Stream[Quads+4] := _Code64[B[L+2] mod 64+1];
Inc(Quads, 4);
if Quads = 76 then begin
Stream[0] := #76;
EncLine := Stream+#13#10;
Encoded.Write(EncLine[1], Length(EncLine));
Quads := 0;
end;
end;
end;
end;
{对以2280为模的余数字节流进行编码}
J := (Decoded.Size mod 2280) div 3;
for I := 1 to J do begin
Decoded.Read(B, 3);
Stream[Quads+1] := _Code64[(B[0] div 4)+1];
Stream[Quads+2] := _Code64[(B[0] mod 4)*16 + (B[1] div 16)+1];
Stream[Quads+3] := _Code64[(B[1] mod 16)*4 + (B[2] div 64)+1];
Stream[Quads+4] := _Code64[B[2] mod 64+1];
Inc(Quads, 4);
{每行76个字符}
if Quads = 76 then begin
Stream[0] := #76;
EncLine := Stream+#13#10;
Encoded.Write(EncLine[1], Length(EncLine));
Quads := 0;
end;
end;
{“=”补位}
if (Decoded.Size mod 3) = 2 then begin
Decoded.Read(B, 2);
Stream[Quads+1] := _Code64[(B[0] div 4)+1];
Stream[Quads+2] := _Code64[(B[0] mod 4)*16 + (B[1] div 16)+1];
Stream[Quads+3] := _Code64[(B[1] mod 16)*4 + 1];
Stream[Quads+4] := '=';
Inc(Quads, 4);
end;
if (Decoded.Size mod 3) = 1 then begin
Decoded.Read(B, 1);
Stream[Quads+1] := _Code64[(B[0] div 4)+1];
Stream[Quads+2] := _Code64[(B[0] mod 4)*16 + 1];
Stream[Quads+3] := '=';
Stream[Quads+4] := '=';
Inc(Quads, 4);
end;
Stream[0] := Chr(Quads);
if Quads > 0 then begin
EncLine := Stream+#13#10;
Encoded.Write(EncLine[1], Length(EncLine));
end;
Result := Encoded.Size;
end;
另外其实用Indy控件就不用麻烦直接可以设置AuthenticationType为atLogin
再设置好username和password属性就可以解决服务器验证问题
procedure TForm1.NMSMTP1Connect(Sender: TObject);
begin
NMSMTP1.Transaction('AUTH LOGIN');
NMSMTP1.Transaction(EncodeString(用户名));
NMSMTP1.Transaction(EncodeString(密码));
end;
EncodeString是将字符串进行Base64编码
函数如下:
{对参数Decoded字符串进行Base64编码,返回编码后的字符串}
function EncodeString(Decoded:string):String;
var
mmTemp,mmDecoded:TMemoryStream;
strTemp:TStrings;
begin
mmTemp := TMemoryStream.Create;
mmDecoded:=TMemoryStream.Create;
strTemp:=TStringList.Create;
strTemp.Add(Decoded);
strTemp.SaveToStream(mmTemp);
mmTemp.Position := 0;
{剔除mmTemp从strTemp中带来的字符#13#10}
mmDecoded.CopyFrom(mmTemp,mmTemp.Size-2);
{对mmDecoded进行Base64编码,由mmTemp返回编码后的结果}
EncodeBASE64(mmTemp,mmDecoded);
{获得Base64编码后的字符串}
mmTemp.Position:=0;
strTemp.LoadFromStream(mmTemp);
{返回结果必须从strTemp[0]中获得,如果使用strTemp.Text会
带来不必要的字符#13#10}
Result:=strTemp[0];
end;
function EncodeBASE64(Encoded: TMemoryStream ; Decoded: TMemoryStream): Integer;
const
_Code64: String[64] =
('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');
var
I: LongInt;
B: array[0..2279] of Byte;
J, K, L, M, Quads: Integer;
Stream: string[76];
EncLine: String;
begin
Encoded.Clear;
Stream := ' ';
Quads := 0;
{为提高效率,每2280字节流为一组进行编码}
J := Decoded.Size div 2280;
Decoded.Position := 0;
{对前J*2280个字节流进行编码}
for I := 1 to J do
begin
Decoded.Read(B, 2280);
for M := 0 to 39 do begin
for K := 0 to 18 do begin
L:= 57*M + 3*K;
Stream[Quads+1] := _Code64[(B[L] div 4)+1];
Stream[Quads+2] := _Code64[(B[L] mod 4)*16 + (B[L+1] div 16)+1];
Stream[Quads+3] := _Code64[(B[L+1] mod 16)*4 + (B[L+2] div 64)+1];
Stream[Quads+4] := _Code64[B[L+2] mod 64+1];
Inc(Quads, 4);
if Quads = 76 then begin
Stream[0] := #76;
EncLine := Stream+#13#10;
Encoded.Write(EncLine[1], Length(EncLine));
Quads := 0;
end;
end;
end;
end;
{对以2280为模的余数字节流进行编码}
J := (Decoded.Size mod 2280) div 3;
for I := 1 to J do begin
Decoded.Read(B, 3);
Stream[Quads+1] := _Code64[(B[0] div 4)+1];
Stream[Quads+2] := _Code64[(B[0] mod 4)*16 + (B[1] div 16)+1];
Stream[Quads+3] := _Code64[(B[1] mod 16)*4 + (B[2] div 64)+1];
Stream[Quads+4] := _Code64[B[2] mod 64+1];
Inc(Quads, 4);
{每行76个字符}
if Quads = 76 then begin
Stream[0] := #76;
EncLine := Stream+#13#10;
Encoded.Write(EncLine[1], Length(EncLine));
Quads := 0;
end;
end;
{“=”补位}
if (Decoded.Size mod 3) = 2 then begin
Decoded.Read(B, 2);
Stream[Quads+1] := _Code64[(B[0] div 4)+1];
Stream[Quads+2] := _Code64[(B[0] mod 4)*16 + (B[1] div 16)+1];
Stream[Quads+3] := _Code64[(B[1] mod 16)*4 + 1];
Stream[Quads+4] := '=';
Inc(Quads, 4);
end;
if (Decoded.Size mod 3) = 1 then begin
Decoded.Read(B, 1);
Stream[Quads+1] := _Code64[(B[0] div 4)+1];
Stream[Quads+2] := _Code64[(B[0] mod 4)*16 + 1];
Stream[Quads+3] := '=';
Stream[Quads+4] := '=';
Inc(Quads, 4);
end;
Stream[0] := Chr(Quads);
if Quads > 0 then begin
EncLine := Stream+#13#10;
Encoded.Write(EncLine[1], Length(EncLine));
end;
Result := Encoded.Size;
end;
另外其实用Indy控件就不用麻烦直接可以设置AuthenticationType为atLogin
再设置好username和password属性就可以解决服务器验证问题
#5
最近刚写好一个邮件收发程序
有兴趣的话可以发给你看看
不过现在还再测试期
有兴趣的话可以发给你看看
不过现在还再测试期
#6
我的邮箱是jxLee365@126.com
#1
procedure TForm1.Button1Click(Sender: TObject);
begin
NMSMTP1.Host := 'mail.host.com';
NMSMTP1.UserID := 'Username';
NMSMTP1.Connect;
NMSMTP1.PostMessage.FromAddress := 'webmaster@swissdelphicenter.ch';
NMSMTP1.PostMessage.ToAddress.Text := 'user@host.com';
NMSMTP1.PostMessage.ToCarbonCopy.Text := 'AnotherUser@host.com';
NMSMTP1.PostMessage.ToBlindCarbonCopy.Text := 'AnotherUser@host.com';
NMSMTP1.PostMessage.Body.Text := 'This is the message';
NMSMTP1.PostMessage.Attachments.Text := 'c:\File.txt';
NMSMTP1.PostMessage.Subject := 'Mail subject';
NMSMTP1.SendMail;
ShowMessage('Mail sent !');
NMSMTP1.Disconnect;
end;
begin
NMSMTP1.Host := 'mail.host.com';
NMSMTP1.UserID := 'Username';
NMSMTP1.Connect;
NMSMTP1.PostMessage.FromAddress := 'webmaster@swissdelphicenter.ch';
NMSMTP1.PostMessage.ToAddress.Text := 'user@host.com';
NMSMTP1.PostMessage.ToCarbonCopy.Text := 'AnotherUser@host.com';
NMSMTP1.PostMessage.ToBlindCarbonCopy.Text := 'AnotherUser@host.com';
NMSMTP1.PostMessage.Body.Text := 'This is the message';
NMSMTP1.PostMessage.Attachments.Text := 'c:\File.txt';
NMSMTP1.PostMessage.Subject := 'Mail subject';
NMSMTP1.SendMail;
ShowMessage('Mail sent !');
NMSMTP1.Disconnect;
end;
#2
系统显示‘用户未验证’。
是不是与SMTP服务器有关?
自己怎样设置自己的SMTP服务器?
是不是与SMTP服务器有关?
自己怎样设置自己的SMTP服务器?
#3
说明服务器需要用户验证
设置auth属性、发送者信箱、密码,且发送者须是该服务器的用户
设置auth属性、发送者信箱、密码,且发送者须是该服务器的用户
#4
添加NMSMTP1的OnConnect事件代码
procedure TForm1.NMSMTP1Connect(Sender: TObject);
begin
NMSMTP1.Transaction('AUTH LOGIN');
NMSMTP1.Transaction(EncodeString(用户名));
NMSMTP1.Transaction(EncodeString(密码));
end;
EncodeString是将字符串进行Base64编码
函数如下:
{对参数Decoded字符串进行Base64编码,返回编码后的字符串}
function EncodeString(Decoded:string):String;
var
mmTemp,mmDecoded:TMemoryStream;
strTemp:TStrings;
begin
mmTemp := TMemoryStream.Create;
mmDecoded:=TMemoryStream.Create;
strTemp:=TStringList.Create;
strTemp.Add(Decoded);
strTemp.SaveToStream(mmTemp);
mmTemp.Position := 0;
{剔除mmTemp从strTemp中带来的字符#13#10}
mmDecoded.CopyFrom(mmTemp,mmTemp.Size-2);
{对mmDecoded进行Base64编码,由mmTemp返回编码后的结果}
EncodeBASE64(mmTemp,mmDecoded);
{获得Base64编码后的字符串}
mmTemp.Position:=0;
strTemp.LoadFromStream(mmTemp);
{返回结果必须从strTemp[0]中获得,如果使用strTemp.Text会
带来不必要的字符#13#10}
Result:=strTemp[0];
end;
function EncodeBASE64(Encoded: TMemoryStream ; Decoded: TMemoryStream): Integer;
const
_Code64: String[64] =
('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');
var
I: LongInt;
B: array[0..2279] of Byte;
J, K, L, M, Quads: Integer;
Stream: string[76];
EncLine: String;
begin
Encoded.Clear;
Stream := ' ';
Quads := 0;
{为提高效率,每2280字节流为一组进行编码}
J := Decoded.Size div 2280;
Decoded.Position := 0;
{对前J*2280个字节流进行编码}
for I := 1 to J do
begin
Decoded.Read(B, 2280);
for M := 0 to 39 do begin
for K := 0 to 18 do begin
L:= 57*M + 3*K;
Stream[Quads+1] := _Code64[(B[L] div 4)+1];
Stream[Quads+2] := _Code64[(B[L] mod 4)*16 + (B[L+1] div 16)+1];
Stream[Quads+3] := _Code64[(B[L+1] mod 16)*4 + (B[L+2] div 64)+1];
Stream[Quads+4] := _Code64[B[L+2] mod 64+1];
Inc(Quads, 4);
if Quads = 76 then begin
Stream[0] := #76;
EncLine := Stream+#13#10;
Encoded.Write(EncLine[1], Length(EncLine));
Quads := 0;
end;
end;
end;
end;
{对以2280为模的余数字节流进行编码}
J := (Decoded.Size mod 2280) div 3;
for I := 1 to J do begin
Decoded.Read(B, 3);
Stream[Quads+1] := _Code64[(B[0] div 4)+1];
Stream[Quads+2] := _Code64[(B[0] mod 4)*16 + (B[1] div 16)+1];
Stream[Quads+3] := _Code64[(B[1] mod 16)*4 + (B[2] div 64)+1];
Stream[Quads+4] := _Code64[B[2] mod 64+1];
Inc(Quads, 4);
{每行76个字符}
if Quads = 76 then begin
Stream[0] := #76;
EncLine := Stream+#13#10;
Encoded.Write(EncLine[1], Length(EncLine));
Quads := 0;
end;
end;
{“=”补位}
if (Decoded.Size mod 3) = 2 then begin
Decoded.Read(B, 2);
Stream[Quads+1] := _Code64[(B[0] div 4)+1];
Stream[Quads+2] := _Code64[(B[0] mod 4)*16 + (B[1] div 16)+1];
Stream[Quads+3] := _Code64[(B[1] mod 16)*4 + 1];
Stream[Quads+4] := '=';
Inc(Quads, 4);
end;
if (Decoded.Size mod 3) = 1 then begin
Decoded.Read(B, 1);
Stream[Quads+1] := _Code64[(B[0] div 4)+1];
Stream[Quads+2] := _Code64[(B[0] mod 4)*16 + 1];
Stream[Quads+3] := '=';
Stream[Quads+4] := '=';
Inc(Quads, 4);
end;
Stream[0] := Chr(Quads);
if Quads > 0 then begin
EncLine := Stream+#13#10;
Encoded.Write(EncLine[1], Length(EncLine));
end;
Result := Encoded.Size;
end;
另外其实用Indy控件就不用麻烦直接可以设置AuthenticationType为atLogin
再设置好username和password属性就可以解决服务器验证问题
procedure TForm1.NMSMTP1Connect(Sender: TObject);
begin
NMSMTP1.Transaction('AUTH LOGIN');
NMSMTP1.Transaction(EncodeString(用户名));
NMSMTP1.Transaction(EncodeString(密码));
end;
EncodeString是将字符串进行Base64编码
函数如下:
{对参数Decoded字符串进行Base64编码,返回编码后的字符串}
function EncodeString(Decoded:string):String;
var
mmTemp,mmDecoded:TMemoryStream;
strTemp:TStrings;
begin
mmTemp := TMemoryStream.Create;
mmDecoded:=TMemoryStream.Create;
strTemp:=TStringList.Create;
strTemp.Add(Decoded);
strTemp.SaveToStream(mmTemp);
mmTemp.Position := 0;
{剔除mmTemp从strTemp中带来的字符#13#10}
mmDecoded.CopyFrom(mmTemp,mmTemp.Size-2);
{对mmDecoded进行Base64编码,由mmTemp返回编码后的结果}
EncodeBASE64(mmTemp,mmDecoded);
{获得Base64编码后的字符串}
mmTemp.Position:=0;
strTemp.LoadFromStream(mmTemp);
{返回结果必须从strTemp[0]中获得,如果使用strTemp.Text会
带来不必要的字符#13#10}
Result:=strTemp[0];
end;
function EncodeBASE64(Encoded: TMemoryStream ; Decoded: TMemoryStream): Integer;
const
_Code64: String[64] =
('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');
var
I: LongInt;
B: array[0..2279] of Byte;
J, K, L, M, Quads: Integer;
Stream: string[76];
EncLine: String;
begin
Encoded.Clear;
Stream := ' ';
Quads := 0;
{为提高效率,每2280字节流为一组进行编码}
J := Decoded.Size div 2280;
Decoded.Position := 0;
{对前J*2280个字节流进行编码}
for I := 1 to J do
begin
Decoded.Read(B, 2280);
for M := 0 to 39 do begin
for K := 0 to 18 do begin
L:= 57*M + 3*K;
Stream[Quads+1] := _Code64[(B[L] div 4)+1];
Stream[Quads+2] := _Code64[(B[L] mod 4)*16 + (B[L+1] div 16)+1];
Stream[Quads+3] := _Code64[(B[L+1] mod 16)*4 + (B[L+2] div 64)+1];
Stream[Quads+4] := _Code64[B[L+2] mod 64+1];
Inc(Quads, 4);
if Quads = 76 then begin
Stream[0] := #76;
EncLine := Stream+#13#10;
Encoded.Write(EncLine[1], Length(EncLine));
Quads := 0;
end;
end;
end;
end;
{对以2280为模的余数字节流进行编码}
J := (Decoded.Size mod 2280) div 3;
for I := 1 to J do begin
Decoded.Read(B, 3);
Stream[Quads+1] := _Code64[(B[0] div 4)+1];
Stream[Quads+2] := _Code64[(B[0] mod 4)*16 + (B[1] div 16)+1];
Stream[Quads+3] := _Code64[(B[1] mod 16)*4 + (B[2] div 64)+1];
Stream[Quads+4] := _Code64[B[2] mod 64+1];
Inc(Quads, 4);
{每行76个字符}
if Quads = 76 then begin
Stream[0] := #76;
EncLine := Stream+#13#10;
Encoded.Write(EncLine[1], Length(EncLine));
Quads := 0;
end;
end;
{“=”补位}
if (Decoded.Size mod 3) = 2 then begin
Decoded.Read(B, 2);
Stream[Quads+1] := _Code64[(B[0] div 4)+1];
Stream[Quads+2] := _Code64[(B[0] mod 4)*16 + (B[1] div 16)+1];
Stream[Quads+3] := _Code64[(B[1] mod 16)*4 + 1];
Stream[Quads+4] := '=';
Inc(Quads, 4);
end;
if (Decoded.Size mod 3) = 1 then begin
Decoded.Read(B, 1);
Stream[Quads+1] := _Code64[(B[0] div 4)+1];
Stream[Quads+2] := _Code64[(B[0] mod 4)*16 + 1];
Stream[Quads+3] := '=';
Stream[Quads+4] := '=';
Inc(Quads, 4);
end;
Stream[0] := Chr(Quads);
if Quads > 0 then begin
EncLine := Stream+#13#10;
Encoded.Write(EncLine[1], Length(EncLine));
end;
Result := Encoded.Size;
end;
另外其实用Indy控件就不用麻烦直接可以设置AuthenticationType为atLogin
再设置好username和password属性就可以解决服务器验证问题
#5
最近刚写好一个邮件收发程序
有兴趣的话可以发给你看看
不过现在还再测试期
有兴趣的话可以发给你看看
不过现在还再测试期
#6
我的邮箱是jxLee365@126.com