|
楼主 |
发表于 2007-1-30 10:52:06
|
显示全部楼层
引入了编译也报错帮忙看下什么问题
var
SendMailExchang: TMessageExchanger; //用于发送邮件的交换机
lAccount: TMailAccount;
MailSystem: TMailSystem;
lMailContent: TMemoryStream;
lMessage: TMessage;
begin
MailSystem := TMailSystem.Create;
SendMailExchang := TMessageExchanger.Create(nil);
lMessage := TMessage.Create(nil);
lAccount := TMailAccount.Create;
try
SendMailExchang.MessageKind := TMessageKind.mkSend;
lMessage.From := 'xxx@sohu.com'; //发件人
lMessage.SendTo := 'xxx@sohu.com'; //收件人
lMessage.BCC := 'xxx@sohu.com';
lMessage.CC := 'xxx@sohu.com';
lMessage.Subject := '测试邮件'; //邮件标题
lMessage.Body.Text := '这是一封测试邮件!邮件正文'; //正文
lMessage.ContentFormatType := TContentFormatType.ftText; // 设置正文内容格式
lMessage.Date := business.System.SysUtils.DateToStr(business.System.SysUtils.now());
//根据邮件的发件人获取发送邮件的帐号,
//此帐号是从Business邮件系统中设置的帐号中获得的
//如果使用自定义的发送帐户,请重新设置lAccount对象的相关属性
lAccount := MailSystem.FindAccountByAddress(lMessage.From);
if lAccount <> nil then
begin
lMailContent := TMemoryStream.Create; //用于存放邮件的正文
lMailContent.Clear;
lMessage.SaveToStream(lMailContent);
lMailContent.Position := 0; //移动流的指针
try
if lAccount.Verify then
begin
if lAccount.DifferPOP then
SendMailExchang.SMTPMessages.Add(lAccount.VerifyAccount,
lAccount.VerifyPassword, lAccount.SMTPHost,
lMessage.From, lMessage.SendTo, lMailContent, lAccount.SMTPPort)
else
SendMailExchang.SMTPMessages.Add(lAccount.UserID, lAccount.Password,
lAccount.SMTPHost, lMessage.From, lMessage.SendTo, lMailContent,
lAccount.SMTPPort);
end
else
SendMailExchang.SMTPMessages.Add(lAccount.SMTPHost, lMessage.From,
lMessage.SendTo, lMailContent, lAccount.SMTPPort);
finally
lMailContent.Free;
lAccount.Free;
end;
SendMailExchang.Active := True; //发送邮件
end;
finally
lMessage.Free;
MailSystem.Free;
SendMailExchang.Free; // SendMailExchang对象一定要最后释放
end;
end; |
|