Bu örnek kod. Outlook (varsayılan outlook posta yöneticisi) üzerinden mail gönderir. Outlook açık değilken gönderilen mailleri outbox'a atıyor ve outlook açılınca gönderiyor.
Kolay Gelsin.. Unit Send_Mail;
Interface
Uses Mapi;
Procedure SendMail(Subject,Mailtext,
FromName,FromAdress,
ToName,ToAdress tring;
AttachedFileName:TStringList;
DisplayFileNametring;
ShowDialog:boolean);
var
Form1: TForm1;
implementation
// Uses 'a Mapi eklenecek **********************
Procedure TForm1.SendMail(Subject,Mailtext,
FromName,FromAdress,
ToName,ToAdress tring;
AttachedFileName:TStringList;
DisplayFileNametring;
ShowDialog:boolean);
var
MapiMessage : TMapiMessage;
MError : Cardinal;
AlicilarT : Array[0..255] of TMapiRecipDesc;
GondericilerT : TMapiRecipDesc;
EklerT : Array[0..255] of TMapiFileDesc;
I:Integer;
begin
with MapiMessage do begin
ulReserved := 0;
lpszSubject := PChar(Subject);
lpszNoteText := PChar(Mailtext);
lpszMessageType := nil;
lpszDateReceived := nil;
lpszConversationID := nil;
flFlags := 0;
GondericilerT.ulReserved:=0;
GondericilerT.ulRecipClass:=MAPI_ORIG;
GondericilerT.lpszName:= PChar(FromName);
GondericilerT.lpszAddress:= PChar(FromAdress);
GondericilerT.ulEIDSize:=0;
GondericilerT.lpEntryID:=nil;
lpOriginator := @GondericilerT;
nRecipCount := 1;
AlicilarT[0].ulReserved:=0;
AlicilarT[0].ulRecipClass:=MAPI_TO;
AlicilarT[0].lpszName:= PChar(ToName);
AlicilarT[0].lpszAddress:= PChar(ToAdress);
AlicilarT[0].ulEIDSize:=0;
AlicilarT[0].lpEntryID:=nil;
lpRecips := @AlicilarT;
nFileCount :=AttachedFileName.Count;
For I:=0 To AttachedFileName.Count-1 Do
Begin
EklerT.lpszPathName:= PChar(AttachedFilename.Strings);
EklerT.lpszFileName:= PChar(AttachedFileName.Strings);
EklerT.ulReserved:=I;
EklerT.flFlags:=I;
EklerT.nPosition:=Cardinal(-1);
EklerT.lpFileType:=nil;
lpFiles := @EklerT;
End;
end;
Try
if ShowDialog then
MError := MapiSendMail(0, Application.Handle,
MapiMessage, MAPI_DIALOG or MAPI_LOGON_UI, 0)
else
MError := MapiSendMail(0, Application.Handle, MapiMessage, 0,);
Except
Case MError of
MAPI_E_AMBIGUOUS_RECIPIENT:
MessageDlg('XXXX',mterror,[mbok],0);
MAPI_E_ATTACHMENT_NOT_FOUND:
MessageDlg('XX',mterror,[mbok],0);
MAPI_E_ATTACHMENT_OPEN_FAILURE:
MessageDlg('XXX',mterror,[mbok],0);
MAPI_E_BAD_RECIPTYPE:
MessageDlg('XXXX',mterror,[mbok],0);
MAPI_E_FAILURE:
MessageDlg('XXX',mterror,[mbok],0);
MAPI_E_INSUFFICIENT_MEMORY:
MessageDlg('XXX',mterror,[mbok],0);
MAPI_E_LOGIN_FAILURE:
MessageDlg('XXX',mterror,[mbok],0);
MAPI_E_TEXT_TOO_LARGE:
MessageDlg('XXX',mterror,[mbok],0);
MAPI_E_TOO_MANY_FILES:
MessageDlg('XXX',mterror,[mbok],0);
MAPI_E_TOO_MANY_RECIPIENTS:
MessageDlg('XXXX',mterror,[mbok],0);
MAPI_E_UNKNOWN_RECIPIENT:
MessageDlg('XXXX',mterror,[mbok],0);
MAPI_E_USER_ABORT:
MessageDlg('XXXXX',mterror,[mbok],0);
SUCCESS_SUCCESS:
MessageDlg('Mail Gonderildi',mtinformation,[mbok],0);
End;
End;
end;
//***************** Örnek Yordam ***************
procedure TForm1.BitBtn1Click(Sender: TObject);
var
X:String;
FilesX:TStringList;
begin
FilesX:=TStringList.Create;
FilesX.Clear;
FilesX.Add('C:\cheaters.log');
FilesX.Add('C:\Autoexec.bak');
// (Subject, Mailtext, FromName, FromAdress, ToName ,ToAdress, AttachedFileName, DisplayFileName, ShowDialog;
SendMail('Mail Deneme', 'Bu mail, Delphi içinden gönderildi.','Programcı ',
'[email protected]','Alıcı Adı','[email protected]',Filesx ,
' ',False);
end;
Delphi İle Outlook Üzerinden Mail Gönderme
Delphi İle Outlook Üzerinden Mail Gönderme
Konuyu Okuyanlar: 1 Ziyaretçi