Delphi 发送邮件 通过Office Outlook
网上搜到的Delphi邮件发送系统,绝大多数是使用SMTP协议来发送。
但是事实上它们已经过时了,大多数邮件服务器已经屏蔽了Delphi Indy的邮件发送,从而导致Delphi发送不成功。
事实上,让Delphi通过Outlook.Application来发送邮件,也是非常方便的,而且没有那么多的限制。
以下是我目前使用的,我把它写成了个函数,使用的时候调用一下即可。
不过,使用的前提是,你得现在在本地Outlook上配置好一个账户。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
procedure
TForm1
.
SendOutlookMail(
const
Recipient,Title,Body,Attachment:
string
);
const
olMailItem =
0
;
var
Outlook: OleVariant;
vMailItem: variant;
begin
try
Outlook := GetActiveOleObject("Outlook
.
Application");
except
Outlook := CreateOleObject("Outlook
.
Application");
end
;
vMailItem := Outlook
.
CreateItem(olMailItem);
vMailItem
.
Recipients
.
Add(Recipient);
vMailItem
.
Subject := Title;
vMailItem
.
Body := Body;
if
Attachment <>""
then
vMailItem
.
Attachments
.
Add(Attachment);
vMailItem
.
Send;
VarClear(Outlook);
|