使用delphi从outlook获取电子邮件

发布于 2024-11-05 19:28:58 字数 93 浏览 0 评论 0原文

我想知道是否有人知道如何借助 Delphi 代码从 Outlook 获取电子邮件。 我想要得到的是电子邮件的每个部分,例如主题、发件人、附件等。

谨致问候!

I was wondering if anyone knows how to get emails from outlook for example with the help of Delphi code.
What I'd like to get is every part of the email like, subject, sender, attachments etc.

Best Regards!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏花。依旧 2024-11-12 19:28:58

本示例向您展示如何使用 Delphi 提供的 TOutlookApplication 组件通过 Outlook 发送电子邮件。它应该让您了解哪些信息可用于邮件项目。

检测 Outlook 中的邮箱 将告诉您在哪里可以找到当前位于任何邮箱中的电子邮件Outlook 邮箱。

function Send: boolean;
var
  Outlook: TOutlookApplication;
  olNameSpace: NameSpace;
  MailIt: TMailItem;
  AttachedFile: OleVariant;
  i: integer;
  emailaddress: string;
begin
  Result := true;
  Outlook := TOutlookApplication.Create( nil );
  try
    Outlook.ConnectKind := ckNewInstance;
    try
      Outlook.Connect;
      try
        olNameSpace := Outlook.GetNamespace('MAPI');
        olNameSpace.Logon('', '', False, False);
        try

          for i := 0 to FNewUsers.Count - 1 do begin
            MailIt := TMailItem.Create( nil );
            MailIt.ConnectTo( Outlook.CreateItem( olMailItem ) as MailItem );
            try
              emailaddress := TStapper( FNewUsers.Items[i] ).Email;
              if emailaddress = '' then begin
                emailaddress := C_MailUnknownAddress;
              end;
              MailIt.Recipients.Add( emailaddress );
              MailIt.Subject := C_MailSubject;
              MailIt.Body := Format( C_MailBody,
                  [TStapper( FNewUsers.Items[i] ).UserId,
                  TStapper( FNewUsers.Items[i] ).Password] );
              MailIt.Save;
            finally
              MailIt.Free;
            end;
          end;

        finally
          olNameSpace.Logoff;
        end;
      finally
        Outlook.Disconnect;
      end;
    finally
      Outlook.free;
    end;
  except
    on E: Exception do begin
      Result := false;
    end;
  end;
end;

This example shows you how to use the TOutlookApplication component provided with Delphi to send emails with Outlook. It should get you an idea on what information is available for mail items.

Detecting mailboxes in outlook will tell you where you can find the emails that are currently in any Outlook mail boxes.

function Send: boolean;
var
  Outlook: TOutlookApplication;
  olNameSpace: NameSpace;
  MailIt: TMailItem;
  AttachedFile: OleVariant;
  i: integer;
  emailaddress: string;
begin
  Result := true;
  Outlook := TOutlookApplication.Create( nil );
  try
    Outlook.ConnectKind := ckNewInstance;
    try
      Outlook.Connect;
      try
        olNameSpace := Outlook.GetNamespace('MAPI');
        olNameSpace.Logon('', '', False, False);
        try

          for i := 0 to FNewUsers.Count - 1 do begin
            MailIt := TMailItem.Create( nil );
            MailIt.ConnectTo( Outlook.CreateItem( olMailItem ) as MailItem );
            try
              emailaddress := TStapper( FNewUsers.Items[i] ).Email;
              if emailaddress = '' then begin
                emailaddress := C_MailUnknownAddress;
              end;
              MailIt.Recipients.Add( emailaddress );
              MailIt.Subject := C_MailSubject;
              MailIt.Body := Format( C_MailBody,
                  [TStapper( FNewUsers.Items[i] ).UserId,
                  TStapper( FNewUsers.Items[i] ).Password] );
              MailIt.Save;
            finally
              MailIt.Free;
            end;
          end;

        finally
          olNameSpace.Logoff;
        end;
      finally
        Outlook.Disconnect;
      end;
    finally
      Outlook.free;
    end;
  except
    on E: Exception do begin
      Result := false;
    end;
  end;
end;
木森分化 2024-11-12 19:28:58

您可以使用标准 OLE 自动化来访问 Outlook:

var 
  Outlook: OLEVariant;
begin
  try
   Outlook:=GetActiveOleObject('Outlook.Application') ;
  except
   Outlook:=CreateOleObject('Outlook.Application') ;
  end;
  //...
end;

您还可以查看 TurboPower OfficePartner,这是一个与 Office 集成的简单方法。我已经很久没有看过这个项目了,所以它可能已经过时了,但在首页上最新的活动只是几个月前......

You can use standard OLE automation to access Outlook:

var 
  Outlook: OLEVariant;
begin
  try
   Outlook:=GetActiveOleObject('Outlook.Application') ;
  except
   Outlook:=CreateOleObject('Outlook.Application') ;
  end;
  //...
end;

You may also have a look at TurboPower OfficePartner which is an easy way to integrate with Office. I haven't looked at this project for ages, so it might be outdateed, but on the front page the latest activity was only a few months ago...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文