关于email

year2000bug 2003-08-12 01:31:25
var
SupportMail:string;
begin
SupportMail = 'mailto:myemail@163.com?subject=[csdn for delphi]';
ShellExecute(0, nil, PChar(SupportMail), nil, nil, SW_SHOWNORMAL);
end;

这是最简单的email调用.
但是他不能指定附件和正文.
我是想不但要指定对方email地址而且还要指定附件和正文等等.
望各位大虾指教.
...全文
93 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
year2000bug 2003-08-24
  • 打赏
  • 举报
回复
//(1)delphi6中的demo有:好象叫MailDemo
//(2)"C:\PROGRAM FILES\OUTLOOK EXPRESS\MSIMN.EXE" /eml:%1
//(3)利用Mapi接口
//我只是想看看大家还有什么好的idea而已.结贴。。。。
uses
Mapi;

function SendEMail(Handle: THandle; Mail: TStrings): Cardinal;
type
TAttachAccessArray = array [0..0] of TMapiFileDesc;
PAttachAccessArray = ^TAttachAccessArray;
var
MapiMessage: TMapiMessage;
Receip: TMapiRecipDesc;
Attachments: PAttachAccessArray;
AttachCount: Integer;
i1: integer;
FileName: string;
dwRet: Cardinal;
MAPI_Session: Cardinal;
WndList: Pointer;
begin
dwRet := MapiLogon(Handle,
PChar(''),
PChar(''),
MAPI_LOGON_UI or MAPI_NEW_SESSION,
0, @MAPI_Session);

if (dwRet <> SUCCESS_SUCCESS) then
begin
MessageBox(Handle,
PChar('Error while trying to send email'),
PChar('Error'),
MB_ICONERROR or MB_OK);
end
else
begin
FillChar(MapiMessage, SizeOf(MapiMessage), #0);
Attachments := nil;
FillChar(Receip, SizeOf(Receip), #0);

if Mail.Values['to'] <> '' then
begin
Receip.ulReserved := 0;
Receip.ulRecipClass := MAPI_TO;
Receip.lpszName := StrNew(PChar(Mail.Values['to']));
Receip.lpszAddress := StrNew(PChar('SMTP:' + Mail.Values['to']));
Receip.ulEIDSize := 0;
MapiMessage.nRecipCount := 1;
MapiMessage.lpRecips := @Receip;
end;

AttachCount := 0;

for i1 := 0 to MaxInt do
begin
if Mail.Values['attachment' + IntToStr(i1)] = '' then
break;
Inc(AttachCount);
end;

if AttachCount > 0 then
begin
GetMem(Attachments, SizeOf(TMapiFileDesc) * AttachCount);

for i1 := 0 to AttachCount - 1 do
begin
FileName := Mail.Values['attachment' + IntToStr(i1)];
Attachments[i1].ulReserved := 0;
Attachments[i1].flFlags := 0;
Attachments[i1].nPosition := ULONG($FFFFFFFF);
Attachments[i1].lpszPathName := StrNew(PChar(FileName));
Attachments[i1].lpszFileName :=
StrNew(PChar(ExtractFileName(FileName)));
Attachments[i1].lpFileType := nil;
end;
MapiMessage.nFileCount := AttachCount;
MapiMessage.lpFiles := @Attachments^;
end;

if Mail.Values['subject'] <> '' then
MapiMessage.lpszSubject := StrNew(PChar(Mail.Values['subject']));
if Mail.Values['body'] <> '' then
MapiMessage.lpszNoteText := StrNew(PChar(Mail.Values['body']));

WndList := DisableTaskWindows(0);
try
Result := MapiSendMail(MAPI_Session, Handle,
MapiMessage, MAPI_DIALOG, 0);
finally
EnableTaskWindows( WndList );
end;

for i1 := 0 to AttachCount - 1 do
begin
StrDispose(Attachments[i1].lpszPathName);
StrDispose(Attachments[i1].lpszFileName);
end;

if Assigned(MapiMessage.lpszSubject) then
StrDispose(MapiMessage.lpszSubject);
if Assigned(MapiMessage.lpszNoteText) then
StrDispose(MapiMessage.lpszNoteText);
if Assigned(Receip.lpszAddress) then
StrDispose(Receip.lpszAddress);
if Assigned(Receip.lpszName) then
StrDispose(Receip.lpszName);
MapiLogOff(MAPI_Session, Handle, 0, 0);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
mail: TStringList;
begin
mail := TStringList.Create;
try
mail.values['to'] := 'Receiver-Email@test.xyz';
mail.values['subject'] := 'Hello';
mail.values['body'] := 'blah';
mail.values['body'] := 'blah';
mail.values['attachment0'] := 'C:\Test.txt';
// mail.values['attachment1']:='C:\Test2.txt';
sendEMail(Application.Handle, mail);
finally
mail.Free;
end;
end;
sixgj 2003-08-12
  • 打赏
  • 举报
回复
呵呵,建议看前几期的《电脑报》!
上面有个这方面的例子。
x_qiang 2003-08-12
  • 打赏
  • 举报
回复
建议用LCmail元件

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧