补位}
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 div 16)+1];
Stream[Quads+3] := _Code64[(B 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, Length(EncLine));
end;
Result := Encoded.Size;
end;
{对参数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;
procedure TForm1.btnOpenClick(Sender: TObject);
begin
{打开对话框,选择SWF文件}
if OpenDialog1.Execute then
begin
end;
end;
procedure TForm1.btnSendClick(Sender: TObject);
var
mmSwfFile,mmEncoded:TMemoryStream;
iResult:Integer;
strsTemp:TStrings;
strContents:TStringList;
i:Integer;
begin
{验证用户输入信息}
if txtTo.Text='''' then
begin
ShowMessage(''请输入收信人!'');
Exit;
end;
if txtFrom.Text='''' then
begin
ShowMessage(''请输入发信人!'');
Exit;
end;
if txtSmtpServer.Text='''' then
begin
ShowMessage(''请输入SMTP服务器!'');
Exit;
end;
if txtPort.Text='''' then
begin
ShowMessage(''请输入端口号!'');
Exit;
end;
if txtSwfFile.Text='''' then
begin
ShowMessage(''请选择SWF文件!'');
Exit;
end;
{检验服务器认证的用户名和密码}
if chkSmtpVerify.Checked = True then
if (txtUserName.Text='''') or (txtPassword.Text='''') then
begin
ShowMessage(''您已选择SMTP服务器需要认证''+#13#10+''请输入用户名和密码!'');
Exit;
end;
{设置SMTP服务器地址、端口}
NMSMTP1.Host:=txtSmtpServer.Text;
NMSMTP1.Port:=StrToInt(txtPort.Text);
{断开原来的连接,保证TForm1.NMSMTP1Connect中服务器认证的执行}
if NMSMTP1.Connected then
begin
NMSMTP1.Disconnect;
end;
{连接服务器}
NMSMTP1.Connect;
{创建流}
mmSwfFile:=TMemoryStream.Create;
mmEncoded:=TMemoryStream.Create;
{加载文件至流mmSwfFile}
mmSwfFile.LoadFromFile(txtSwfFile.Text);
{对mmSwfFile进行Base64编码,mmEncoded为编码后内容}
iResult:=EncodeBASE64(mmEncoded,mmSwfFile);
strsTemp:=TStringList.Create;
mmEncoded.Position:=0;
strsTemp.LoadFromStream(mmEncoded);
{----生成邮件内容----}
strContents:=TStringList.Create;
strContents.Add(''--------------SwfEmail by JDH'');
strContents.Add(''Content-Type: text/html; charset=gb2312'');
strContents.Add(''Content-Transfer-Encoding: 8bit'');
{注意:空行是邮件格式所必需的!}
strContents.Add('''');
strContents.Add(''< HTML>&