Este ejemplo muestra cómo usar el componente TOutlookApplication proporcionado con Delphi para enviar correos electrónicos con Outlook. Debería hacerte una idea de qué información está disponible para los artículos de correo.
Detecting mailboxes in outlook le dirá dónde puede encontrar los correos electrónicos que se encuentran actualmente en cualquier buzón de Outlook.
function Send: boolean;
var
Outlook: TOutlookApplication;
olNameSpace: NameSpace;
MailIt: TMailItem;
AttachedFile: OleVariant;
i: integer;
emailaddress: string;
begin
Result := true;
Outlook := TOutlookApplication.Create(nil);
try
Outlook.ConnectKind := ckNewInstance;
try
Outlook.Connect;
try
olNameSpace := Outlook.GetNamespace('MAPI');
olNameSpace.Logon('', '', False, False);
try
for i := 0 to FNewUsers.Count - 1 do begin
MailIt := TMailItem.Create(nil);
MailIt.ConnectTo(Outlook.CreateItem(olMailItem) as MailItem);
try
emailaddress := TStapper(FNewUsers.Items[i]).Email;
if emailaddress = '' then begin
emailaddress := C_MailUnknownAddress;
end;
MailIt.Recipients.Add(emailaddress);
MailIt.Subject := C_MailSubject;
MailIt.Body := Format(C_MailBody,
[TStapper(FNewUsers.Items[i]).UserId,
TStapper(FNewUsers.Items[i]).Password]);
MailIt.Save;
finally
MailIt.Free;
end;
end;
finally
olNameSpace.Logoff;
end;
finally
Outlook.Disconnect;
end;
finally
Outlook.free;
end;
except
on E: Exception do begin
Result := false;
end;
end;
end;