G
gy0050a
Unregistered / Unconfirmed
GUEST, unregistred user!
function SendEmail(Handle: THandle; Mail: TStrings): Cardinal;<br>//调用MAPI发送Email<br>type<br> TAttachAccessArray = array [0..0] of TMapiFileDesc;<br> PAttachAccessArray = ^TAttachAccessArray;<br>var<br> MapiMessage : TMapiMessage;<br> Receip : TMapiRecipDesc;<br> Attachments : PAttachAccessArray;<br> AttachCount : Integer;<br> iCount : Integer;<br> FileName : string;<br>begin<br> FillChar(MapiMessage, SizeOf(MapiMessage), #0);<br> Attachments := nil;<br> FillChar(Receip,SizeOf(Receip), #0);<br> if Mail.Values['to'] <> '' then begin<br> Receip.ulReserved := 0;<br> Receip.ulRecipClass := MAPI_TO;<br> Receip.lpszName := StrNew(PChar(Mail.Values['to']));<br> Receip.lpszAddress := StrNew(PChar('SMTP:' + Mail.Values['to']));<br> Receip.ulEIDSize := 0;<br> MapiMessage.nRecipCount := 1;<br> MapiMessage.lpRecips := @Receip;<br> end;<br><br> AttachCount := 0;<br> for iCount := 0 to MaxInt do begin<br> if Mail.Values['attachment' + IntToStr(iCount)] = '' then Break;<br> AttachCount := AttachCount + 1;<br> end;<br><br> if AttachCount > 0 then begin<br> GetMem(Attachments,SizeOf(TMapiFileDesc) * AttachCount);<br> for iCount := 0 to (AttachCount - 1) do begin<br> FileName := Mail.Values['attachment' + IntToStr(iCount)];<br> Attachments[iCount].ulReserved := 0;<br> Attachments[iCount].flFlags := 0;<br> Attachments[iCount].nPosition := ULONG($FFFFFFFF);<br> Attachments[iCount].lpszPathName := StrNew(PChar(FileName));<br> Attachments[iCount].lpszFileName := StrNew(PChar(ExtractFileName(FileName)));<br> Attachments[iCount].lpFileType := nil;<br> end;<br> MapiMessage.nFileCount := AttachCount;<br> MapiMessage.lpFiles := @Attachments^;<br> end;<br><br> if Mail.Values['subject'] <> '' then<br> MapiMessage.lpszSubject := StrNew(PChar(Mail.Values['subject']));<br> if Mail.Values['body'] <> '' then<br> MapiMessage.lpszNoteText := StrNew(PChar(Mail.Values['body']));<br><br> Result := MapiSendMail(0, Handle, MapiMessage, MAPI_DIALOG*Ord(Handle <> 0) OR MAPI_LOGON_UI OR MAPI_NEW_SESSION, 0);<br><br> for iCount := 0 to (AttachCount - 1) do begin<br> strDispose(Attachments[iCount].lpszPathName);<br> strDispose(Attachments[iCount].lpszFileName);<br> end;<br><br> if assigned(MapiMessage.lpszSubject) then<br> strDispose(MapiMessage.lpszSubject);<br> if assigned(MapiMessage.lpszNoteText) then<br> strDispose(MapiMessage.lpszNoteText);<br> if assigned(Receip.lpszAddress) then<br> strDispose(Receip.lpszAddress);<br> if assigned(Receip.lpszName) then<br> strDispose(Receip.lpszName);<br>end;<br><br>procedure TFrmPrintReport.FlatButton3Click(Sender: TObject);<br>var<br> mail : TStringList;<br>begin<br> mail := TStringList.Create;<br> try<br> //以下邮箱<br> mail.Values['to'] := EmailAdderss;<br> //以下主题<br> mail.Values['subject'] := '主题...';<br> //以下内容<br> mail.Values['body'] := '内容.....';<br> //以下附件<br> mail.Values['attachment0'] :='c:/test.txt' ;<br><br> SendEmail(Application.Handle, mail);<br> finally<br> mail.Free;<br> end;<br><br><br>end;