繁体   English   中英

使用Thunderbird从Delphi发送邮件

[英]Sending mail from Delphi using Thunderbird

我处于一种需要使用Thunderbird和Delphi XE3发送带有附件的电子邮件的情况,我不知道从哪里开始,所以我问是否有人链接到我可以找到信息的网站。

从文档中,您可以使用Thunderbird的命令行选项 ,因此我认为使用ShellExecute应该可以。 我还没有尝试过。

ShellExecute(Handle, 'path\to\thunderbird.exe',
    '-compose "to=foo@nowhere.net,attachment=''file:///c:/test.txt''", 
    nil, SW_SHOWNORMAL);

以下代码基于这两篇文章:

脚步:

将一个FileListBox和一个按钮放在窗体上,并将FileListBox MultiSelect属性设置为true。 使用此代码将文件列表框中的选定条目传递给默认邮件应用程序。

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, FileCtrl;

type
  TForm1 = class(TForm)
    FileListBox1: TFileListBox;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

uses
  ActiveX, ShlObj, ComObj;

{$R *.dfm}

function GetFileListDataObject(const Directory: string; Files:
  TStrings):
  IDataObject;
type
  PArrayOfPItemIDList = ^TArrayOfPItemIDList;
  TArrayOfPItemIDList = array[0..0] of PItemIDList;
var
  Malloc: IMalloc;
  Root: IShellFolder;
  FolderPidl: PItemIDList;
  Folder: IShellFolder;
  p: PArrayOfPItemIDList;
  chEaten: ULONG;
  dwAttributes: ULONG;
  FileCount: Integer;
  i: Integer;
begin
  Result := nil;
  if Files.Count = 0 then
    Exit;
  OleCheck(SHGetMalloc(Malloc));
  OleCheck(SHGetDesktopFolder(Root));
  OleCheck(Root.ParseDisplayName(0, nil,
    PWideChar(WideString(Directory)),
    chEaten, FolderPidl, dwAttributes));
  try
    OleCheck(Root.BindToObject(FolderPidl, nil, IShellFolder,
      Pointer(Folder)));
    FileCount := Files.Count;
    p := AllocMem(SizeOf(PItemIDList) * FileCount);
    try
      for i := 0 to FileCount - 1 do
      begin
        OleCheck(Folder.ParseDisplayName(0, nil,
          PWideChar(WideString(Files[i])), chEaten, p^[i],
          dwAttributes));
      end;
      OleCheck(Folder.GetUIObjectOf(0, FileCount, p^[0], IDataObject,
        nil,
        Pointer(Result)));
    finally
      for i := 0 to FileCount - 1 do
      begin
        if p^[i] <> nil then
          Malloc.Free(p^[i]);
      end;
      FreeMem(p);
    end;
  finally
    Malloc.Free(FolderPidl);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  SelFileList: TStrings;
  I: Integer;
  DataObject: IDataObject;
  Effect: Integer;
  CLSID_SendMail: TGUID;
  DT: IDropTarget;
  P: TPoint;
begin
  CLSID_SendMail := StringToGUID('{9E56BE60-C50F-11CF-9A2C-00A0C90A90CE}');

  with FileListBox1 do
  begin
    SelFileList := TStringList.Create;
    try
      SelFileList.Capacity := SelCount;
      for i := 0 to FileListBox1.Items.Count - 1 do
        if Selected[i] then
          SelFileList.Add(Items[i]);
      DataObject := GetFileListDataObject(Directory, SelFileList);
    finally
      SelFileList.Free;
    end;
    Effect := DROPEFFECT_NONE;
    CoCreateInstance(CLSID_SendMail, nil, CLSCTX_ALL, IDropTarget, DT);
    DT.DragEnter(DataObject, MK_LBUTTON, P, Effect);
    DT.Drop(DataObject, MK_LBUTTON, P, Effect);
  end;
end;

end.

(在Delphi 2009中测试)


我的原始博客文章: http : //mikejustin.wordpress.com/2009/07/03/how-can-i-simulate-send-to-with-delphi/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM