VB的代码:通过API函数ShellExecute再加上一些参数就可以实现发送带附件的邮件,下面是范例:
Option Explicit Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Const SW_SHOW = 5 Private Sub Command1_Click()
Debug.Print "[email protected]?subject=MySubject&Attach=""""c:\doc1.doc"""""
Call ShellExecute(Me.hwnd, "open", _
"[email protected]?subject=MySubject&Attach=""c:\doc1.doc""", _
vbNullString, vbNullString, SW_SHOW)
End Sub
上面的程序将 c:\doc1.doc 作为附件发送出去,上面的代码在OutLook 2000以及 Outlook Exress 5.5下运行通过自己改一下,很简单的。
Option Explicit Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Private Const SW_SHOW = 5 Private Sub Command1_Click()
Debug.Print "[email protected]?subject=MySubject&Attach=""""c:\doc1.doc"""""
Call ShellExecute(Me.hwnd, "open", _
"[email protected]?subject=MySubject&Attach=""c:\doc1.doc""", _
vbNullString, vbNullString, SW_SHOW)
End Sub
上面的程序将 c:\doc1.doc 作为附件发送出去,上面的代码在OutLook 2000以及 Outlook Exress 5.5下运行通过自己改一下,很简单的。
解决方案 »
- 非常简单的一句SQL语句,参数问题
- 关于idHttp的几个问题,请各位帮忙解答一下!先谢了!
- 求超市连锁配送系统的文档资料及涉及的表单
- 急!关于Adoquery的问题
- 如何提取QQ里的QQwry.dat的IP來原信息呢,他不是一個dbf
- 请教各位斑竹与高手:关于ActiveX控件
- 这个问题很有挑战性
- 请问我在Dehpi 6 下写代码,输入英文正常,但中文不能输入,为什么呀,可从没碰到过呀
- 改个名字,交个朋友,散分,斑竹别删,拜托!!
- 江湖救急 100分 delphi7 indy demos chat 客户端一运行就死机怎么回事啊??
- 在线等待,给分,急,急!!!!!!!!
- 请问如何将String变量类型转换为TForm变量类型。谢谢!
mailto:<address_of_the_receiver>?cc=<whom_a_copy> &bcc=<whom_a_hidden_copy>&subject=<subject_of_the_message> &body=<text_of_the_message>你看看
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q197782
好像不那么简单
var attachs:tstringlist;
begin
attachs:= TStringList.Create;
attachs.add('C:\aaa.txt');
attachs.add('C:\bbb.txt');
attachs.add('C:\ccc.txt'); //三个附件
try
SendByEmail('收件人','标题','内容',attachs);
//SendByEmail(Recipients,subjexts,body,attachs);
finally
attachs.free;
end;
end;function SendByEmail(recip,subjects,bodys:string;attachs:TStringList):boolean;
var mail: TStringList;
str,str1:string;
j:integer;
begin
result:=false;
str:=''; str1:='';
mail := TStringList.Create;
mail.values['to'] := recip;
mail.values['subject'] := subjects;
mail.values['body'] := bodys;
try
for j:=0 to attachs.Count-1 do
begin
str:=attachs.Strings[j];
str1:='attachment'+inttostr(j);
mail.values[str1] := str;
end;
SendEMail(Application.Handle, mail);
finally
mail.Free;
end;
result:=true;
end;
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;
iCount : INTEGER;
FileName : STRING;
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 iCount := 0 TO MaxInt
DO
BEGIN
IF Mail.Values['attachment' + IntToStr(iCount)] = ''
THEN
BREAK;
AttachCount := AttachCount + 1;
END;
IF AttachCount > 0
THEN
BEGIN
GetMem(Attachments,SizeOf(TMapiFileDesc) * AttachCount);
FOR iCount := 0 TO (AttachCount - 1)
DO
BEGIN
FileName := Mail.Values['attachment' + IntToStr(iCount)];
Attachments[iCount].ulReserved := 0;
Attachments[iCount].flFlags := 0;
Attachments[iCount].nPosition := ULONG($FFFFFFFF);
Attachments[iCount].lpszPathName := StrNew(PChar(FileName));
Attachments[iCount].lpszFileName := StrNew(PChar(ExtractFileName(FileName)));
Attachments[iCount].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'])); Result := MapiSendMail(0, Handle, MapiMessage,MAPI_DIALOG*Ord(Handle <> 0) OR MAPI_LOGON_UI OR MAPI_NEW_SESSION, 0); FOR iCount := 0 TO (AttachCount - 1)
DO
BEGIN
strDispose(Attachments[iCount].lpszPathName);
strDispose(Attachments[iCount].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);
END;