用outlook或foxmail写邮件,代码怎么写? ( 积分: 100 )

  • 主题发起人 主题发起人 尹兆兵
  • 开始时间 开始时间

尹兆兵

Unregistered / Unconfirmed
GUEST, unregistred user!
用outlook或foxmail写邮件,代码怎么写?
 
用outlook或foxmail写邮件,代码怎么写?
 
// uses ComObj,Dialogs

function TForm1.SendMailWithAttachments(Email, Subject : string; Body : Widestring ; Filename : string): boolean;

var

outlook : variant;

item : variant;

begin

try

outlook := CreateOLEObject('outlook.application');

try

item := outlook.CreateItem(0);

item.Subject := Subject;

// You can use "Body := Memo1.text".

item.Body := Body;

// You can add more Attachments by adding the same line.

item.Attachments.Add(FileName,1,1,FileName);

item.To := email;

item.Send;

finally

// To make sure Outlook don't stay open.

outlook.quit;

end;

except

result := false;

exit;

end;

result := true;

end;

// Here is an example how the function works.

procedure TForm1.Button1Click(Sender: TObject);

var

Opendialog1 : TOpenDialog;



begin

// Create an OpenDialog to get the Attachment.

// Is the Dialogs unit in the uses line?

Opendialog1 := TOpendialog.Create(application);

try

if OpenDialog1.Execute then

begin

SendMailWithAttachments('Info@Cleys.com', 'Delphi3000 function','Have fun!',opendialog1.FileName);

end;

finally

Opendialog1.Destroy;

end;

end;
 
网上来的.正确与否有待验证.
如果有哥们提供更好的或已经运行通过的,请发给小弟,不胜感激!
(zql177@yahoo.com.cn)
 
我你试试
 
to cx0522:
大哥,有什么好的代码啊.可以发给小弟吗?zql177@yahoo.com.cn
 
接受答案了.
 
后退
顶部