Цитата(maleziv @ 21.2.2012, 10:45) | Доброго времени суток уважаемые. С прикреплением в коде программы Копии письма разобрался. Прошу помочь разобраться в следующем: После запуска программы письмо остается в Microsoft Office Outlook 2003 в папке Исходящие, а не отправляется сразу заданным адресатам в программе, что не есть хорошо. Подскажите в чем может быть дело, почему письмо не отправляется сразу, может быть дело не в коде вовсе, а в Outlook-е(в нем где покрутить)?
PS: После того как письмо отсалось в папке Исходящие, через некоторое время Outlook делает синхронизацию(Отправка и получение) с почтовым ящиком и письмо лежавшее в папке Исходящие спокойно и без ошибок уходит само, но это не есть хорошо, так как нужна немедленная отправка программным путем.
Код | unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, mapi,Clipbrd, ComCtrls;
type TForm1 = class(TForm) Button1: TButton; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm} function SendEMail(Handle: THandle; Mail: TStrings): Cardinal; type TAttachAccessArray = array [0..0] of TMapiFileDesc; PAttachAccessArray = ^TAttachAccessArray; var MapiMessage: TMapiMessage; Receip: array of TMapiRecipDesc; dwRet: Cardinal; MAPI_Session: Cardinal; WndList: Pointer; Attachment: TMapiFileDesc; begin Result := 0;
dwRet := MapiLogon(Handle, '', '', MAPI_NEW_SESSION, 0, @MAPI_Session); if (dwRet <> SUCCESS_SUCCESS) then begin
MessageBox(Handle, PChar('Почтовый клиент, заданный по умолчанию, не обнаружен'), PChar('Ошибка'), MB_ICONERROR or MB_OK); end else begin FillChar(MapiMessage, SizeOf(MapiMessage), #0); FillChar(Receip, SizeOf(Receip), #0); if Mail.Values['to'] <> '' then begin SetLength(Receip, 1); Receip[0].ulReserved := 0; Receip[0].ulRecipClass := MAPI_TO; Receip[0].lpszName := StrNew(PChar(Mail.Values['to'])); Receip[0].lpszAddress := StrNew(PChar('SMTP:' + Mail.Values['to'])); Receip[0].ulEIDSize := 0; if Mail.Values['cc'] <> '' then begin SetLength(Receip, 2); Receip[1].ulReserved := 0; Receip[1].ulRecipClass := MAPI_CC; Receip[1].lpszName := StrNew(PChar(Mail.Values['cc'])); Receip[1].lpszAddress := StrNew(PChar('SMTP:' + Mail.Values['cc'])); Receip[1].ulEIDSize := 0; MapiMessage.nRecipCount := 2; end else MapiMessage.nRecipCount := 1; MapiMessage.lpRecips := @Receip[0]; 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'])); { if Mail.Values['attachment'] <> '' then begin ZeroMemory(@Attachment, SizeOf(TMapiFileDesc)); Attachment.nPosition := DWORD(-1); Attachment.lpszPathName := PChar(Mail.Values['attachment']); Attachment.lpszFileName := PChar(ExtractFileName(Mail.Values['attachment'])); MapiMessage.nFileCount := 1; MapiMessage.lpFiles := @Attachment; end; } WndList := DisableTaskWindows(0); try Result := MapiSendMail(MAPI_Session, Handle, MapiMessage, 0, 0);
finally EnableTaskWindows(WndList); end; if Assigned(MapiMessage.lpszSubject) then StrDispose(MapiMessage.lpszSubject); if Assigned(MapiMessage.lpszNoteText) then StrDispose(MapiMessage.lpszNoteText); if Assigned(Receip[0].lpszAddress) then StrDispose(Receip[0].lpszAddress); if Assigned(Receip[0].lpszName) then StrDispose(Receip[0].lpszName); if Mail.Values['cc'] <> '' then begin if Assigned(Receip[1].lpszAddress) then StrDispose(Receip[1].lpszAddress); if Assigned(Receip[1].lpszName) then StrDispose(Receip[1].lpszName); end; MapiLogOff(MAPI_Session, Handle, 0, 0); end; end; procedure TForm1.FormCreate(Sender: TObject); var mail: TStringList; begin mail := TStringList.Create; try
mail.values['to'] :='[email protected]'; mail.values['cc'] :='[email protected]'; mail.values['subject'] := 'message'; mail.values['body'] := ' '; sendEMail(Application.Handle, mail); finally mail.Free; end;
end;
end.
|
|
На этой ветке форума есть кто живой?? |