我使用 JclMapi.pas 使用 MAPI 发送电子邮件。我编写了一个类来简化 TJclEmail 类的使用。
发送电子邮件的代码是:
class function TMAPISendMail.Execute(const Name, EmailTo, Subject, Body: string; Attachment: TStrings): boolean;
var
I: Integer;
Email: string;
MAPISendMail: TMAPISendMail;
begin
MAPISendMail:= TMAPISendMail.Create;
try
I:= 1;
while I > 0 do
begin
Email:= TString.Token(EmailTo, ';', I);
if Email <> '' then
MAPISendMail.AddRecipient(Email, Name);
end;
for I := 0 to Attachment.Count - 1 do
MAPISendMail.AddAttachment(Attachment[I]);
MAPISendMail.MailSubject:= Subject;
MAPISendMail.HTMLBody:= False;
MAPISendMail.MailBody:= Body;
Result:= MAPISendMail.SendMail;
finally
MAPISendMail.Free;
end;
end;
类接口是:
TMAPISendMail = class
private
FAJclEmail: TJclEmail;
FPrerequisites: TPrerequisites;
FResolveNames: Boolean;
FShowDialog: Boolean;
[...]
protected
function DoSendMail: Boolean; virtual;
public
constructor Create;
destructor Destroy; override;
class function Execute(const Name, EmailTo, Subject, Body: string; Attachment: TStrings): boolean; static;
property MailBody: string read GetMailBody write SetMailBody;
property HTMLBody: Boolean read GetHTMLBody write SetHTMLBody;
property ShowDialog: Boolean read FShowDialog write FShowDialog;
property MailSubject: string read GetMailSubject write SetMailSubject;
property ResolveNames: Boolean read FResolveNames write FResolveNames;
property Prerequisites: TPrerequisites read FPrerequisites;
procedure AddRecipient(const Address: string; const Name: string = '');
procedure AddAttachment(const FileName: string);
function SendMail: Boolean;
end;
希望它对你有用。
也检查这个线程:发送带有签名的电子邮件