1楼是外部邮件,内部邮件参考
uses
MAILLIBRARY;
procedure TfrmSendMail.SendMail1;
var
MailGUID, MailPath: string;
lStream: TStream;
begin
lStream := TMemoryStream.Create;
MailGUID := jsCommon.CreateGUIDStr;
MailPath := 'BIZ_DRAFT';
try
//生成邮件内容
SaveToStream('ZS', edtRec.Text, '', '', edtSub.Text, memo1.Text, lStream);
//保存邮件到发件箱
SaveMail(mailGuid, mailPath, lStream);
//发送内部邮件
TMailSystem.CreateMailSystem.SendInternalMail(MailGuid, edtRec.Text, 0, 0);
//移动发件箱信息到已发送邮箱
TMailSystem.CreateMailSystem.MoveMail(MailGUID, 'BIZ_OUTBOX', 'BIZ_SENTBOX');
finally
lStream.Free;
end;
end;
procedure TfrmSendMail.SaveToStream(Const AFrom, ASendTo, ACC, ABcc, ASubject,
ABodyText: String; var AStream: TStream);
var
msgMail: TMessage;
begin
msgMail := TMessage.Create(self);
try
msgMail.From := AFrom;
msgMail.SendTo := ASendTo;
msgMail.CC := ACC;
msgMail.Bcc := ABcc;
msgMail.Subject := ASubject;
msgMail.Body.Text := ABodyText;
msgMail.SaveToStream(AStream);
finally
msgMail.Free;
end;
end;
procedure TfrmSendMail.SaveMail(var MailGUID, MailPath: string; AStream: TStream);
var
lMailRef: TMailReference;
lContent: TStream;
lAttachments: TObjectList;
lMailGUID, lMailPath: string;
begin
lMailGUID := MailGUID;
//保存的路径
lMailPath := 'BIZ_OUTBOX';
lMailRef := TMailReference.Create;
lMailRef.MailGUID := lMailGUID;
lMailRef.MailInfo.MailGUID := lMailGUID;
lMailRef.MailInfo.UIDL := jsCommon.CreateGUIDStr;
lMailRef.PathGUID := lMailPath;
lContent := TMemoryStream.Create;
lAttachments := TObjectList.Create(True);
AStream.Position := 0;
TMailSystem.CreateMailSystem.MsgStreamToMail(lMailRef, lContent, lAttachments, AStream);
lMailRef.MailInfo.Date := SysUtils.Now;
lMailRef.Time := lMailRef.MailInfo.Date;
lMailRef.State := 2;
//保存邮件
TMailSystem.CreateMailSystem.SaveMail(lMailRef, lContent, lAttachments);
MailPath := lMailPath;
MailGUID := lMailGUID;
end; |