起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 139|回复: 5

请帮忙解决一下,还是邮件发送问题**

[复制链接]
发表于 2008-8-29 15:14:33 | 显示全部楼层 |阅读模式
procedure TMainForm.Button1Click(Sender: TObject);
var
  SendMailExchang: TMessageExchanger;
  lMessage: TMessage;
  lAccount, FAccount: TMailAccount;
  MailSystem: TMailSystem;
  lMailContent: TMemoryStream;
begin
  SendMailExchang := TMessageExchanger.Create(nil);
  lMessage := TMessage.Create(nil);
  lAccount := TMailAccount.Create;
  MailSystem := TMailSystem.Create;
  FAccount := MailSystem.Accounts[0];
    try
    SendMailExchang.MessageKind := TMessageKind.mkSend;
    lAccount.SMTPHost := FAccount.SMTPHost;
    lAccount.SMTPPort := FAccount.SMTPPort;
    lAccount.POPHost := FAccount.POPHost;
    lAccount.POPPort := FAccount.POPPort;
    lAccount.MailAddress := FAccount.MailAddress;
    lAccount.UserID := FAccount.UserID;
    lAccount.Password := FAccount.Password;
    lAccount.AccountID := FAccount.AccountID;
    lAccount.Verify := True;
    //lAccount.VerifyAccount := 'oaleer@163.com';
    //lAccount.VerifyPassword := '******';
    lMessage.From := FAccount.MailAddress;  //发件人
    lMessage.SendTo := 'OAleer@163.com';  //收件人
    lMessage.Subject := '告警提示!';             //mail tatil
    lMessage.Body.Text := '邮件测试,多多打扰请见谅!';
    lMessage.ContentFormatType := TContentFormatType.ftHTML;  // 设置正文内容格式
    //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;  //发送邮件   
    //dialogs.showmessage('邮件发送成功!');     注释掉这句就收不到邮件了,不知道为什么
    end;
  finally
    lMessage.Free;
    MailSystem.Free;
    SendMailExchang.Free;  //  SendMailExchang对象一定要最后释放
  end;
end;
回复

使用道具 举报

发表于 2008-8-29 15:41:06 | 显示全部楼层
您重启建模工具,编译下这个窗体,再试试
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-8-29 16:03:23 | 显示全部楼层
试了,还是收不到。
回复 支持 反对

使用道具 举报

发表于 2008-8-30 15:42:37 | 显示全部楼层
。。。
回复 支持 反对

使用道具 举报

发表于 2008-8-30 15:49:03 | 显示全部楼层
回复 支持 反对

使用道具 举报

发表于 2008-9-1 11:02:55 | 显示全部楼层
楼主问题怎么样了?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2025-7-21 15:47 , Processed in 0.037888 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表