delphi 简单的发送邮件
2013-07-16 23:24
387 查看
delphi编程用outlook发送邮件的方法,以下是关键代码:
// 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(xuedelphi@163.com', 'I Love Eva Zhang','She Is My Wife!',opendialog1.FileName);
end;
finally
Opendialog1.Destroy;
end;
end;
// 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(xuedelphi@163.com', 'I Love Eva Zhang','She Is My Wife!',opendialog1.FileName);
end;
finally
Opendialog1.Destroy;
end;
end;
相关文章推荐
- Delphi通过IdSmtp发送邮件的简单代码
- ASP.NET使用SMTP协议简单的发送邮件(支持附件)
- asp.net带附件功能的简单发送邮件
- 一个简单的自动发送邮件系统(三)
- 使用java在本地服务器实现简单的邮件的发送与接受
- JAVA邮件发送的简单实现
- 邮件发送简单例子-jsp文件
- Spring mail 邮件发送的简单实现
- JavaMail 简单发送邮件
- java发送邮件简单实现以及原理(亲…
- Delphi发送邮件
- 基于JavaMail的Java邮件发送:简单邮件发送
- asp.net最简单的邮件自动发送
- javamail设置多个收件人发送简单文本邮件
- winform中简单的邮件发送(c++/cli)
- 基于JavaMail的Java邮件发送:简单邮件发送
- java 简单邮件发送 & 常遇问题总结
- javamail发送邮件的简单实例
- 简单的发送邮件代码
- 黑马程序员--邮件开发(简单邮件发送,复制邮件发送,直接发送已经生成好的邮件)