我可以借用一个mail2000的控件才保存成eml文件的,给你看一段把邮件通过mail2000保存成eml的例子
//Óʼþ±¸·Ý
procedure TServiceForm.BackupMail;
var
MailSeq: Integer;
MailMessage: TMailMessage2000;
OaId: string;
AttachedFileName: string;
TmpLst: TStrings;
Directory: string;
Contenttype: string;
Loop: Integer;
begin
//±¸·ÝÓʼþ
Memo.Lines.Add(StringOfChar('*', 80));
Memo.Lines.Add(FormatDateTime('yyyy-mm-dd hh:mm:ss', Now) + ' ¿ªÊ¼¼ì²éÓʼþ±¸·Ý...');
Memo.Lines.Add(StringOfChar('*', 80));
ADOQueryBackupTask.Active := True;
//È¡±¸·ÝÈÎÎñ
while not ADOQueryBackupTask.Eof do
begin
OaId := ADOQueryBackupTask.FieldByName('oaid').AsString;
Directory := ADOQueryBackupTask.FieldByName('backupdirectory').AsString;
//Èç¹ûĿ¼²»´æÔÚ£¬Ôò½¨Á¢±¸·ÝĿ¼
if Directory[Length(Directory)] <> '/' then
Directory := Directory + '/';
if not DirectoryExists(Copy(Directory, 1, Length(Directory) - 1)) then
ForceDirectories(Copy(Directory, 1, Length(Directory) - 1));
ADOQueryBackupLst.Active := False;
ADOQueryBackupLst.Parameters.ParamByName('foaid').Value := OaId;
ADOQueryBackupLst.Active := True;
Memo.Lines.Add(FormatDateTime('yyyy-mm-dd hh:mm:ss', Now) + ' &iquest;&ordf;&Ecirc;&frac14;&frac14;ì&sup2;é ' + OaId + ' &micro;&Auml;&Oacute;&Ecirc;&frac14;&thorn;±&cedil;·&Yacute;...');
while not ADOQueryBackupLst.Eof do
begin
//&Egrave;&iexcl;&cedil;&Atilde;oa&Oacute;&Atilde;&raquo;§&Ograve;&ordf;±&cedil;·&Yacute;&micro;&Auml;&Oacute;&Ecirc;&frac14;&thorn;mailseq
MailSeq := AdoQueryBackupLst.FieldByName('mailseq').AsInteger;
ADOQueryBackupMailbox.Active := False;
ADOQueryBackupMailbox.Parameters.ParamByName('mailseq').Value := MailSeq;
ADOQueryBackupMailbox.Active := True;
TmpLst := TStringList.Create;
//&Egrave;&iexcl;&Oacute;&Ecirc;&frac14;&thorn;&Aacute;&ETH;±í
while not ADOQueryBackupMailbox.Eof do
begin
MailMessage := TMailMessage2000.Create(nil);
//&Eacute;ú&sup3;&Eacute;&Oacute;&Ecirc;&frac14;&thorn;&Iacute;·
MailMessage.SetFrom(ADOQueryBackupMailbox.FieldByName('ffrom').AsString, '');
MailMessage.SetReplyTo(ADOQueryBackupMailbox.FieldByName('freplyto').AsString, '');
MailMessage.Subject := ADOQueryBackupMailbox.FieldByName('fsubject').AsString;
//&Atilde;&raquo;°ì·¨&acute;&brvbar;&Agrave;í&Ecirc;±&frac14;&auml;&cedil;&ntilde;&Ecirc;&frac12;&pound;&not;&Ouml;&raquo;&Auml;&Uuml;&Oacute;&Atilde;&micro;±&Ccedil;°&Ecirc;±&frac14;&auml;&Agrave;&acute;&acute;ú&Igrave;&aelig;
MailMessage.Date := StrToDateTime(ADOQueryBackupMailbox.FieldByName('fdate').AsString);
MailMessage.AddTo(ADOQueryBackupMailbox.FieldByName('fsendto').AsString, '');
MailMessage.AddCc(ADOQueryBackupMailbox.FieldByName('fcc').AsString, '');
MailMessage.AddBcc(ADOQueryBackupMailbox.FieldByName('fbcc').AsString, '');
//×&Ouml;·&ucirc;&frac14;&macr;&Ccedil;&iquest;&Ouml;&AElig;&Ecirc;&sup1;&Oacute;&Atilde;&Ouml;&ETH;&Icirc;&Auml;
MailMessage.Charset := 'GB2312';
//&Ecirc;&sup1;&Oacute;&Atilde;&Oacute;&Ecirc;&frac14;&thorn;×&Ocirc;&frac14;&ordm;&micro;&Auml;×&Ouml;·&ucirc;&frac14;&macr;
//MailMessage.Charset:=AdoQueryMailBox.FieldByName('fcharset').AsString;
//&Eacute;ú&sup3;&Eacute;&Oacute;&Ecirc;&frac14;&thorn;&Igrave;&aring;
Contenttype := ADOQueryBackupMailbox.FieldByName('fcontenttype').AsString;
TmpLst.Text := ADOQueryBackupMailbox.FieldByName('ftext').Value;
if Pos('TEXT/HTML', Contenttype) = 0 then
//&micro;±×÷html&Oacute;&Ecirc;&frac14;&thorn;
MailMessage.SetTextHTML(TmpLst)
else
//&micro;±×÷text&Oacute;&Ecirc;&frac14;&thorn;
MailMessage.SetTextPlain(TmpLst);
//&Egrave;&ccedil;&sup1;&ucirc;&Oacute;&ETH;&cedil;&frac12;&frac14;&thorn;
if ADOQueryBackupMailbox.FieldByName('fattachedfiles').AsString = '0' then
begin
//&Eacute;ú&sup3;&Eacute;&cedil;&frac12;&frac14;&thorn;±í
ADOQueryBackupAttachedFiles.Active := False;
ADOQueryBackupAttachedFiles.Parameters.ParamByName('mailseq').Value := MailSeq;
ADOQueryBackupAttachedFiles.Active := True;
//&Eacute;ú&sup3;&Eacute;&Oacute;&Ecirc;&frac14;&thorn;&cedil;&frac12;&frac14;&thorn;&sup2;&iquest;·&Ouml;
while not ADOQueryBackupAttachedFiles.Eof do
begin
AttachedFileName := ADOQueryBackupAttachedFiles.FieldByName('attchedfilename').AsString;
//&Egrave;&ccedil;&sup1;&ucirc;&cedil;&frac12;&frac14;&thorn;&Ecirc;&Ccedil;&acute;&aelig;&Ocirc;&Uacute;&micro;&Auml;,&Ocirc;ò&Eacute;ú&sup3;&Eacute;Message&cedil;&frac12;&frac14;&thorn;
if FileExists(AttachedFileName) then
begin
//&Ocirc;&ouml;&frac14;&Oacute;&cedil;&frac12;&frac14;&thorn;
MailMessage.AttachFile(AttachedFileName);
//&frac12;&acirc;&Acirc;&euml;
for Loop := 0 to MailMessage.AttachList.Count - 1 do
if MailMessage.AttachList[Loop].Decoded.Size = 0 then
MailMessage.AttachList[Loop].Decode;
end;
ADOQueryBackupAttachedFiles.Next;
end;
ADOQueryBackupAttachedFiles.Active := False;
//&Ocirc;&ouml;&frac14;&Oacute;&cedil;&frac12;&frac14;&thorn;&ordm;ó&Ouml;&Oslash;&ETH;&Acirc;&Eacute;ú&sup3;&Eacute;body
MailMessage.RebuildBody;
end;
MailMessage.SaveToFile(Directory + FormatDateTime('yyyymmddhhmmss', Now) + '.eml');
MailMessage.Free;
ADOQueryBackupMailbox.Next;
end;
ADOQueryBackupMailbox.Active := False;
TmpLst.Free;
Memo.Lines.Add(FormatDateTime('yyyy-mm-dd hh:mm:ss', Now) + ' &frac12;á&Ecirc;&oslash;&frac14;ì&sup2;é ' + OaId + ' &micro;&Auml;&Oacute;&Ecirc;&frac14;&thorn;±&cedil;·&Yacute;...');
ADOQueryBackupLst.Next;
end;
ADOQueryBackupLst.Active := False;
//&Eacute;&frac34;&sup3;&yacute;±&cedil;·&Yacute;&Oacute;&Ecirc;&frac14;&thorn;&Aacute;&ETH;±í
ADOQueryDelBackupLst.Active := False;
ADOQueryDelBackupLst.Parameters.ParamByName('oaid').Value := OaId;
ADOQueryDelBackupLst.ExecSQL;
//±ê&Ouml;&frac34;&cedil;&Atilde;±&cedil;·&Yacute;&Egrave;&Icirc;&Icirc;&ntilde;&Ecirc;&Ccedil;·&ntilde;&Ograve;&Ntilde;&Iacute;ê&sup3;&Eacute;
ADOQueryBackupTask.Edit;
ADOQueryBackupTask.FieldByName('Flag').Value := '0';
ADOQueryBackupTask.Post;
ADOQueryBackupTask.Next;
end;
ADOQueryBackupTask.Active := False;
//&Eacute;&frac34;&sup3;&yacute;±&cedil;·&Yacute;&Egrave;&Icirc;&Icirc;&ntilde;&Ouml;&ETH;&Ograve;&Ntilde;&frac34;&shy;&frac12;&oslash;&ETH;&ETH;&sup1;&yacute;±&cedil;·&Yacute;&micro;&Auml;&Egrave;&Icirc;&Icirc;&ntilde;
ADOQueryDelBackupTask.Active := False;
ADOQueryDelBackupTask.Parameters.ParamByName('flag').Value := '0';
ADOQueryDelBackupTask.ExecSQL;
Memo.Lines.Add(StringOfChar('*', 80));
Memo.Lines.Add(FormatDateTime('yyyy-mm-dd hh:mm:ss', Now) + ' &frac12;á&Ecirc;&oslash;&frac14;ì&sup2;é&Oacute;&Ecirc;&frac14;&thorn;±&cedil;·&Yacute;... ');
Memo.Lines.Add(StringOfChar('*', 80));
end;