delphi调用OUTLOOK发送DBGRID中的数据(注意不是OUTLOOK EXPRESS ),带显示发送邮件界面。
2007-01-18 01:21
661 查看
{在网上搜了很久,发现DELPHI7.0调用OUTLOOK都没有提如何显示发送邮件界面,后来发现WINDOWS自带的VBAOUTL9.CHM 里面有详细的说明。
示范代码:
}
unit SendMailForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ComCtrls, StdCtrls, Menus,OriFormat, DB, ADODB, jpeg,printers,Mapi,Math,
OleServer, Excel2000,clipbrd,StrUtils, Grids, DBGrids,ComObj, ActiveX,
NavatorPanel, MapiControl;
type
TSendMailForm= class(TForm)
button1:Tbutton;
DataSource1: TDataSource;
DBGrid1: Tdbgrid;
Adoquery1:Tadoquery;
procedure button1onclick(sender:Tobject);
private
{ Private declarations }
public
{ Public declarations }
procedure exportdbgridtoemail(dbgrid: Tdbgrid);
end;
var
SendMailForm: TSendMailForm;
implementation
{$R *.dfm}
procedure TSendMailForm.exportdbgridtoemail(dbgrid: Tdbgrid);
var
Outlook, NmSpace, Folder: OleVariant;
miMail: Variant;
s:string;
MapiControl1:TMapiControl;
const
olMailItem = 0;
function dbgridtohtmls(dbgrid:tdbgrid):string;
var s:string;
i:integer;
begin
s:='<html><body>'; //
s:=s+'<hr>' ;
s:=s+'<table /border="1" bordercolor="#000080">'; //
with dbgrid.DataSource.DataSet do
begin
DisableControls;
first;
s:=s+'<tr align="left">';//
for i:=0 to dbgrid.FieldCount-1 do
if dbgrid.findcolumn(dbgrid.Fields[i].FieldName).Visible then
if ((dbgrid.DataSource.DataSet.Fields[i].DataType<>ftGuid) and (dbgrid.DataSource.DataSet.Fields[i].DataType<>ftBlob)) then
s:=s+'<td>'+dbgrid.DataSource.DataSet.Fields[i].DisplayLabel+'</td>';
// nowrap
s:=s+'</tr>' ;
while not eof do
begin
s:=s+''+'<tr align="left">';////<br>
for i:=0 to dbgrid.FieldCount-1 do
begin
if dbgrid.findcolumn(dbgrid.Fields[i].FieldName).Visible then
if ((dbgrid.DataSource.DataSet.Fields[i].DataType<>ftGuid) and (dbgrid.DataSource.DataSet.Fields[i].DataType<>ftBlob)) then
begin
if dbgrid.DataSource.DataSet.Fields[i].IsNull then
s:=s+'<td nowrap> </td>'
else
if dbgrid.DataSource.DataSet.Fields[i].AsString='' then
s:=s+'<td nowrap> </td>'
else
s:=s+'<td nowrap>'+dbgrid.DataSource.DataSet.Fields[i].asstring+'</td>';
end;
end;
//exit;
s:=s+'</tr>';
next;
end;
//s:=s+'<tr><td>'+BottomMemo+'</td></tr>';
EnableControls;
end;
//s:=s+'<tr>xx</tr>';
s:=s+'</table>';
s:=s+'</body></html>';
//
result:=s;
end;
begin
inherited;
//showmessage('begin to create');
try
Outlook := CreateOleObject('Outlook.Application');
except
on e:exception do
begin
alert('请检查您电脑上是否安装了Outlook:'+e.Message);
exit;
end;
end;
//showmessage('create ok');
miMail := Outlook.CreateItem(olMailItem);
//miMail.Recipients.Add(INPUTBOX('请输入邮箱地址!','',''));
miMail.Subject := ((self as tform).caption) ;
// use this to send a plain text email (all versions of Outlook)
//miMail.Body := 'Attached is the list of email addresses.';
// alternatively send an HTML email (not in Outlook 97)
//showmessage('make html');
miMail.HTMLBody :=dbgridtohtmls(dbgrid);
//showmessage('html maked');
//'<font color=red>Attached is the <b>list of email</b> addresses.</font>';
//miMail.Attachments.Add('C:/temp/list.txt', EmptyParam, EmptyParam, EmptyParam);
//miMail.Send;
//显示发送邮件的界面。
miMail.Display;
//showmessage('发送完毕!');
end;
procedure TSendMailForm.Button1Click(Sender: TObject);
begin
exportdbgridtoemail(dbgrid1)
end;
end.
//希望对大家有所帮助
示范代码:
}
unit SendMailForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ComCtrls, StdCtrls, Menus,OriFormat, DB, ADODB, jpeg,printers,Mapi,Math,
OleServer, Excel2000,clipbrd,StrUtils, Grids, DBGrids,ComObj, ActiveX,
NavatorPanel, MapiControl;
type
TSendMailForm= class(TForm)
button1:Tbutton;
DataSource1: TDataSource;
DBGrid1: Tdbgrid;
Adoquery1:Tadoquery;
procedure button1onclick(sender:Tobject);
private
{ Private declarations }
public
{ Public declarations }
procedure exportdbgridtoemail(dbgrid: Tdbgrid);
end;
var
SendMailForm: TSendMailForm;
implementation
{$R *.dfm}
procedure TSendMailForm.exportdbgridtoemail(dbgrid: Tdbgrid);
var
Outlook, NmSpace, Folder: OleVariant;
miMail: Variant;
s:string;
MapiControl1:TMapiControl;
const
olMailItem = 0;
function dbgridtohtmls(dbgrid:tdbgrid):string;
var s:string;
i:integer;
begin
s:='<html><body>'; //
s:=s+'<hr>' ;
s:=s+'<table /border="1" bordercolor="#000080">'; //
with dbgrid.DataSource.DataSet do
begin
DisableControls;
first;
s:=s+'<tr align="left">';//
for i:=0 to dbgrid.FieldCount-1 do
if dbgrid.findcolumn(dbgrid.Fields[i].FieldName).Visible then
if ((dbgrid.DataSource.DataSet.Fields[i].DataType<>ftGuid) and (dbgrid.DataSource.DataSet.Fields[i].DataType<>ftBlob)) then
s:=s+'<td>'+dbgrid.DataSource.DataSet.Fields[i].DisplayLabel+'</td>';
// nowrap
s:=s+'</tr>' ;
while not eof do
begin
s:=s+''+'<tr align="left">';////<br>
for i:=0 to dbgrid.FieldCount-1 do
begin
if dbgrid.findcolumn(dbgrid.Fields[i].FieldName).Visible then
if ((dbgrid.DataSource.DataSet.Fields[i].DataType<>ftGuid) and (dbgrid.DataSource.DataSet.Fields[i].DataType<>ftBlob)) then
begin
if dbgrid.DataSource.DataSet.Fields[i].IsNull then
s:=s+'<td nowrap> </td>'
else
if dbgrid.DataSource.DataSet.Fields[i].AsString='' then
s:=s+'<td nowrap> </td>'
else
s:=s+'<td nowrap>'+dbgrid.DataSource.DataSet.Fields[i].asstring+'</td>';
end;
end;
//exit;
s:=s+'</tr>';
next;
end;
//s:=s+'<tr><td>'+BottomMemo+'</td></tr>';
EnableControls;
end;
//s:=s+'<tr>xx</tr>';
s:=s+'</table>';
s:=s+'</body></html>';
//
result:=s;
end;
begin
inherited;
//showmessage('begin to create');
try
Outlook := CreateOleObject('Outlook.Application');
except
on e:exception do
begin
alert('请检查您电脑上是否安装了Outlook:'+e.Message);
exit;
end;
end;
//showmessage('create ok');
miMail := Outlook.CreateItem(olMailItem);
//miMail.Recipients.Add(INPUTBOX('请输入邮箱地址!','',''));
miMail.Subject := ((self as tform).caption) ;
// use this to send a plain text email (all versions of Outlook)
//miMail.Body := 'Attached is the list of email addresses.';
// alternatively send an HTML email (not in Outlook 97)
//showmessage('make html');
miMail.HTMLBody :=dbgridtohtmls(dbgrid);
//showmessage('html maked');
//'<font color=red>Attached is the <b>list of email</b> addresses.</font>';
//miMail.Attachments.Add('C:/temp/list.txt', EmptyParam, EmptyParam, EmptyParam);
//miMail.Send;
//显示发送邮件的界面。
miMail.Display;
//showmessage('发送完毕!');
end;
procedure TSendMailForm.Button1Click(Sender: TObject);
begin
exportdbgridtoemail(dbgrid1)
end;
end.
//希望对大家有所帮助
相关文章推荐
- 继承于CCObject,而非CCLayer的界面的显示(注意,不是调用静态函数)
- outlook生成mag文件(不是收到的邮件啊,而是新建邮件生成msg文件)/网页上调用的mag文件直接发送邮件的msg文件是怎么生成的?/写好收件人的mag文件是怎么生成的?
- 利用python调用elasticsearch-api来分析数据并作图进行日报邮件发送
- 利用python调用elasticsearch-api来分析数据并作图进行日报邮件发送
- SAP中用json数据格式调用http接口发送短信邮件案例
- C# winform 通过调用outlook发送邮件
- delphi2010发送邮件—中文显示为乱码解决
- SAP中用json数据格式调用http接口发送短信邮件案例
- iOS 调用系统短信、邮件发送界面
- 利用python调用elasticsearch-api来分析数据并作图进行日报邮件发送
- 利用python调用elasticsearch-api来分析数据并作图进行日报邮件发送
- c# 调用outlook发送邮件
- 在SQL Server中,使用CDONTS发送邮件,并让发件人显示姓名而不是单纯的邮件地址
- C# 调用outlook 发送邮件 或添加附件发送
- 调用系统界面发送短信和邮件
- C# 调用outlook 发送邮件
- C# 调用outlook 发送邮件 或添加附件发送
- 调用OutLook发送邮件
- 利用python调用elasticsearch-api来分析数据并作图进行日报邮件发送
- 针对C#调用OutLook发送邮件模块出现的各类问题解决方案