如何实现用delphi访问outlook express的收发邮件箱中的邮件?

unit MapiControl; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; type { Introducing a new Type of Event to get the Errorcode } TMapiErrEvent = procedure(Sender: TObject; ErrCode: Integer) of object; TMapiControl = class(TComponent) constructor Create(AOwner: TComponent); override; destructor Destroy; override; private { Private-Deklarationen } FSubject: string; FMailtext: string; FFromName: string; FFromAdress: string; FTOAdr: TStrings; FCCAdr: TStrings; FBCCAdr: TStrings; FAttachedFileName: TStrings; FDisplayFileName: TStrings; FShowDialog: Boolean; FUseAppHandle: Boolean; { Error Events: } FOnUserAbort: TNotifyEvent; FOnMapiError: TMapiErrEvent; FOnSuccess: TNotifyEvent; { +> Changes by Eugene Mayevski [mailto:Mayevski@eldos.org]} procedure SetToAddr(newValue : TStrings); procedure SetCCAddr(newValue : TStrings); procedure SetBCCAddr(newValue : TStrings); procedure SetAttachedFileName(newValue : TStrings); { +< Changes } protected { Protected-Deklarationen } public { Public-Deklarationen } ApplicationHandle: THandle; procedure Sendmail(); procedure Reset(); published { Published-Deklarationen } property Subject: string read FSubject write FSubject; property Body: string read FMailText write FMailText; property FromName: string read FFromName write FFromName; property FromAdress: string read FFromAdress write FFromAdress; property Recipients: TStrings read FTOAdr write SetTOAddr; property CopyTo: TStrings read FCCAdr write SetCCAddr; property BlindCopyTo: TStrings read FBCCAdr write SetBCCAddr; property AttachedFiles: TStrings read FAttachedFileName write SetAttachedFileName; property DisplayFileName: TStrings read FDisplayFileName; property ShowDialog: Boolean read FShowDialog write FShowDialog; property UseAppHandle: Boolean read FUseAppHandle write FUseAppHandle; { Events: } property OnUserAbort: TNotifyEvent read FOnUserAbort write FOnUserAbort; property OnMapiError: TMapiErrEvent read FOnMapiError write FOnMapiError; property OnSuccess: TNotifyEvent read FOnSuccess write FOnSuccess; end; procedure Register; implementation uses Mapi; { Register the component: } procedure Register; begin RegisterComponents('expectIT', [TMapiControl]); end; { TMapiControl } constructor TMapiControl.Create(AOwner: TComponent); begin inherited Create(AOwner); FOnUserAbort := nil; FOnMapiError := nil; FOnSuccess := nil; FSubject := ''; FMailtext := ''; FFromName := ''; FFromAdress := ''; FTOAdr := TStringList.Create; FCCAdr := TStringList.Create; FBCCAdr := TStringList.Create; FAttachedFileName := TStringList.Create; FDisplayFileName := TStringList.Create; FShowDialog := False; ApplicationHandle := Application.Handle; end; procedure TMapiControl.SetToAddr(newValue : TStrings); begin FToAdr.Assign(newValue); end; procedure TMapiControl.SetCCAddr(newValue : TStrings); begin FCCAdr.Assign(newValue); end; procedure TMapiControl.SetBCCAddr(newValue : TStrings); begin FBCCAdr.Assign(newValue); end; procedure TMapiControl.SetAttachedFileName(newValue : TStrings); begin FAttachedFileName.Assign(newValue); end; { +< Changes } destructor TMapiControl.Destroy; begin FTOAdr.Free; FCCAdr.Free; FBCCAdr.Free; FAttachedFileName.Free; FDisplayFileName.Free; inherited destroy; end; { Reset the fields for re-use} procedure TMapiControl.Reset; begin FSubject := ''; FMailtext := ''; FFromName := ''; FFromAdress := ''; FTOAdr.Clear; FCCAdr.Clear; FBCCAdr.Clear; FAttachedFileName.Clear; FDisplayFileName.Clear; end; { Send the Mail via the API, this procedure composes and sends the Email } procedure TMapiControl.Sendmail; var MapiMessage: TMapiMessage; MError: Cardinal; Sender: TMapiRecipDesc; PRecip, Recipients: PMapiRecipDesc; PFiles, Attachments: PMapiFileDesc; i: Integer; AppHandle: THandle; begin { First we store the Application Handle, if not the Component might fail to send the Email or your calling Program gets locked up. } AppHandle := Application.Handle; { We need all recipients to alloc the memory } MapiMessage.nRecipCount := FTOAdr.Count + FCCAdr.Count + FBCCAdr.Count; GetMem(Recipients, MapiMessage.nRecipCount * sizeof(TMapiRecipDesc)); try with MapiMessage do begin ulReserved := 0; { Setting the Subject: } lpszSubject := PChar(Self.FSubject); { ... the Body: } lpszNoteText := PChar(FMailText); lpszMessageType := nil; lpszDateReceived := nil; lpszConversationID := nil; flFlags := 0; { and the sender: (MAPI_ORIG) } Sender.ulReserved := 0; Sender.ulRecipClass := MAPI_ORIG; Sender.lpszName := PChar(FromName); Sender.lpszAddress := PChar(FromAdress); Sender.ulEIDSize := 0; Sender.lpEntryID := nil; lpOriginator := @Sender; PRecip := Recipients; { We have multiple recipients: (MAPI_TO) and setting up each: } if nRecipCount > 0 then begin for i := 1 to FTOAdr.Count do begin PRecip^.ulReserved := 0; PRecip^.ulRecipClass := MAPI_TO; { lpszName should carry the Name like in the contacts or the adress book, I will take the email adress to keep it short: } PRecip^.lpszName := PChar(FTOAdr.Strings[i - 1]); { If you use this component with Outlook97 or 2000 and not some of Express versions you will have to set 'SMTP:' in front of each (email-) adress. Otherwise Outlook/Mapi will try to handle the Email on itself. Sounds strange, just erease the 'SMTP:', compile, compose a mail and take a look at the resulting email adresses (right click). } PRecip^.lpszAddress := PChar('SMTP:' + FTOAdr.Strings[i - 1]); PRecip^.ulEIDSize := 0; PRecip^.lpEntryID := nil; Inc(PRecip); end; { Same with the carbon copy recipients: (CC, MAPI_CC) } for i := 1 to FCCAdr.Count do begin PRecip^.ulReserved := 0; PRecip^.ulRecipClass := MAPI_CC; PRecip^.lpszName := PChar(FCCAdr.Strings[i - 1]); PRecip^.lpszAddress := PChar('SMTP:' + FCCAdr.Strings[i - 1]); PRecip^.ulEIDSize := 0; PRecip^.lpEntryID := nil; Inc(PRecip); end; { ... and the blind copy recipients: (BCC, MAPI_BCC) } for i := 1 to FBCCAdr.Count do begin PRecip^.ulReserved := 0; PRecip^.ulRecipClass := MAPI_BCC; PRecip^.lpszName := PChar(FBCCAdr.Strings[i - 1]); PRecip^.lpszAddress := PChar('SMTP:' + FBCCAdr.Strings[i - 1]); PRecip^.ulEIDSize := 0; PRecip^.lpEntryID := nil; Inc(PRecip); end; end; lpRecips := Recipients; { Now we process the attachments: } if FAttachedFileName.Count > 0 then begin nFileCount := FAttachedFileName.Count; GetMem(Attachments, MapiMessage.nFileCount * sizeof(TMapiFileDesc)); PFiles := Attachments; { Fist setting up the display names (without path): } FDisplayFileName.Clear; for i := 0 to FAttachedFileName.Count - 1 do FDisplayFileName.Add(ExtractFileName(FAttachedFileName[i])); if nFileCount > 0 then begin { Now we pass the attached file (their paths) to the structure: } for i := 1 to FAttachedFileName.Count do begin { Setting the complete Path } Attachments^.lpszPathName := PChar(FAttachedFileName.Strings[i - 1]); { ... and the displayname: } Attachments^.lpszFileName := PChar(FDisplayFileName.Strings[i - 1]); Attachments^.ulReserved := 0; Attachments^.flFlags := 0; { Position has to be -1, please see the WinApi Help for details. } Attachments^.nPosition := Cardinal(-1); Attachments^.lpFileType := nil; Inc(Attachments); end; end; lpFiles := PFiles; end else begin nFileCount := 0; lpFiles := nil; end; end; { Send the Mail, silent or verbose: Verbose means in Express a Mail is composed and shown as setup. In non-Express versions we show the Login-Dialog for a new session and after we have choosen the profile to use, the composed email is shown before sending Silent does currently not work for non-Express version. We have no Session, no Login Dialog so the system refuses to compose a new email. In Express Versions the email is sent in the background. } if FShowDialog then MError := MapiSendMail(0, AppHandle, MapiMessage, MAPI_DIALOG or MAPI_LOGON_UI or MAPI_NEW_SESSION, 0) else MError := MapiSendMail(0, AppHandle, MapiMessage, 0, 0); { Now we have to process the error messages. There are some defined in the MAPI unit please take a look at the unit to get familiar with it. I decided to handle USER_ABORT and SUCCESS as special and leave the rest to fire the "new" error event defined at the top (as generic error) Not treated as special: MAPI_E_AMBIGUOUS_RECIPIENT, MAPI_E_ATTACHMENT_NOT_FOUND, MAPI_E_ATTACHMENT_OPEN_FAILURE, MAPI_E_BAD_RECIPTYPE, MAPI_E_FAILURE, MAPI_E_INSUFFICIENT_MEMORY, MAPI_E_LOGIN_FAILURE, MAPI_E_TEXT_TOO_LARGE, MAPI_E_TOO_MANY_FILES, MAPI_E_TOO_MANY_RECIPIENTS, MAPI_E_UNKNOWN_RECIPIENT: } case MError of MAPI_E_USER_ABORT: begin if Assigned(FOnUserAbort) then FOnUserAbort(Self); end; SUCCESS_SUCCESS: begin if Assigned(FOnSuccess) then FOnSuccess(Self); end else begin if Assigned(FOnMapiError) then FOnMapiError(Self, MError); end; end; finally { Finally we do the cleanups, the message should be on its way } FreeMem(Recipients, MapiMessage.nRecipCount * sizeof(TMapiRecipDesc)); end; end; { Please treat this as free. If you improve the component I would be glad to get a copy. } end.

转载于:https://www.cnblogs.com/xieyunc/archive/2009/04/30/2793649.html

如何实现用Delphi访问Outlook Express的收发邮件箱中的邮件?相关推荐

  1. 使用Gpg4Win+Outlook Express实现发送和接收加密邮件

    一.Gpg4win3.0.3的安装和使用        1.软件简介 Gpg4win是一款Windows平台下基于RSA公钥密码体制,集密钥生成.存储.发布于一体的密钥管理和加解密软件.一共包含Gpg ...

  2. Outlook Express客户端收发雅虎邮件Error logging in .PLEASE visit

    我使用的Outlook Express总出现Error logging in .PLEASE visit http//:mail .yahoo.com 重输口令, 我找到e解决方法了,我真系聪明 客户 ...

  3. OutLook 2010 (Bata) 中的邮件导出功能

    2010年4月22日,MSDN 用户可以通过订阅下载正式版本的Office 2010.首发语言中包括简体中文版.其中产品包括:Office 2010 Professional Plus,Project ...

  4. Outlook Express邮件客户端的自动化配置

    出处:  http://www.cnblogs.com/blodfox777/archive/2009/01/13/1374907.html Outlook Express邮件客户端的自动化配置 在部 ...

  5. 如何备份和还原 Outlook Express 数据

    如何备份 Outlook Express 项 步骤 1:将邮件文件复制到备份文件夹 步骤 A:定位存储文件夹 1.        启动 Outlook Express. 2.        单击&qu ...

  6. 电子邮件服务器名设置方法,电子邮件 outlook express 怎样设置电子邮件服务器名?...

    要想使用Outlook Express(以下简称OE)收发Gmail中的邮件,必须要符合两个条件,一是开启Gmail的POP功能;二是在OE中要按照Gmail的官方要求进行设置.下面我们来看看具体的设 ...

  7. Outlook Express 修复丢失邮件

    我在当时遇到三次这样的情况,试着用网上给出的方法去恢复,但仅恢复了目录,里面的邮件全部没有了,当然网上说也有可以恢复原样的.所以贴出方法以供大家参考 第一种方法 修复工具下载地址:http://dow ...

  8. Outlook Express常见问答

    No 问  题 错误码 1 账号或密码设定错误,无法收信 0x800CCC92 2 外寄服务器设定错误,无法寄信 0x800CCC0D 0x800CCC79 3 收件人地址错误,无法寄信 0x800C ...

  9. 原Outlook Express邮件(winxp sp3)导入到Microsoft Outlook 2010 Beta(Windows 7)

    因为工作原因,原有公司机器(Winxp sp3操作系统)上用Outlook Express 大概保存了4G的邮件(当然是N个.dbx),最近笔记本装了Windows 7和Microsoft Outlo ...

  10. Outlook Express出0x800C0133错误的解决

    一电脑Outlook Express收公司邮箱一直出下面的错误: 出现未知错误. 帐户: 'mail.xxxxxxx.com', 服务器: 'mail.xxxxxxx.com', 协议: POP3, ...

最新文章

  1. python学习笔记 day44 数据库三范式
  2. 使用 XML 时尽量避免使用的技术
  3. python入门练习题-python入门练习题2
  4. 史上最详细Docker安装Redis (含每一步的图解)实战
  5. linux命令--VI命令详解(三)
  6. oracle备份与恢复--闪回技术
  7. 他,是数学天才,是多复变解析函数的创始人
  8. MICCAI 2019 :纪录、风向与学术思考
  9. ActionScript 3 step by step (2) - 使用Trace()跟踪输出
  10. BiCubic双三次插值算法进行上采样python与matlab代码实现
  11. 关于locahost:8080一直在等待却不报错
  12. 关闭和开启笔记本自带键盘。
  13. Python 绘制游戏窗口
  14. c语言%u的作用,C语言中%p,%u,%lu都有什么用处
  15. 海量搜索服务架构搭建2-SolrCloud集群搭建
  16. strchr()函数的详解与实现
  17. poi获取段落位置_apache poi word提取段落
  18. 关于idea中maven jar包冲突的解决方法
  19. RMA( 退货)的业务流程
  20. oracle查询job运行状态,查询当前正在执行的job的情况

热门文章

  1. scala List入门到熟悉
  2. Linux快速查找库文件位置
  3. 如何在分组报表中实现组内数据补空行及组内页码
  4. 注册表实现欢迎界面的修改
  5. flutter实战1:完成一个有侧边栏的主界面
  6. POJ3281:Dining——题解
  7. 10月24日云栖精选夜读:2017杭州·云栖大会完美收官 虚拟化平台精彩回顾
  8. 定时器/计数器0(定时器)
  9. Service Worker 全面进阶
  10. iOS学习笔记32 - 锚点