Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delphi and Send emails from a specific Outlook account

568 views
Skip to first unread message

MilkMonitor

unread,
May 14, 2012, 8:38:04 AM5/14/12
to
I currently have an application, written in Delphi which generates
emails in Outlook without any problems. I am using Delphi 7, which
references the Outlook8 unit. Recently a client of mine requested that
when the email is created, can it default to a specific Outlook
account. Having made searches on the internet, it appears that when
using any version of Outlook prior to version 2007 it is not possible
to create an email and specify the account you want to send it from.
I've also found that within Outlook 2007 and newer that there is a
property called SendUsingAccount.

I've also discovered that there is a way of setting the account
through using the Inspector property.

1. Do you know of a way I can set the account using Inspector for
any version of Outlook prior to Outlook 2007, if so do you have an
example?

2. If I want to integrate the properties of Outlook 2007 and newer
into my application, how would I do this? I can find on the internet
units for Outlook8.pas and Outlook2000.pas but nothing for
Outlook2007.

I'd appreciate any help anyone could give to enable me to send emails
from a specific account.


My current code to send emails via Outlook looks like this:

procedure EmailViaOutlook(sRecipient, sSubject, sBody: string;
sAttachment: Tstrings);
var
Outlook : OutlookApplication;
Unknown : IUnknown;
Result : HResult;
MI : MailItem;
bOutlookRunning: boolean;
i: integer;
const
olMailItem = 0;
begin
// via early binding:
Result := GetActiveObject(CLASS_OutlookApplication, nil, Unknown);

{Check if Outlook is already running, this uses Outlook 2000}
if FindWindow('mspim_wnd32','Microsoft Outlook') <> 0 then
bOutlookRunning := true
else
bOutlookRunning := false;

if Result = MK_E_UNAVAILABLE then
begin
Outlook := CoOutlookApplication.Create;
end
else begin
// make sure no other error occurred during GetActiveObject
OleCheck(Result);
OleCheck(Unknown.QueryInterface(OutlookApplication, Outlook));
end;

MI := Outlook.CreateItem(olMailItem) as MailItem;

if trim(sRecipient) <> '' then
MI.To_ := sRecipient;

for i := 0 to pred(sAttachment.count) do
MI.Attachments.Add(sAttachment[i],EmptyParam, EmptyParam,
EmptyParam);

MI.Subject := sSubject;
MI.Body := sBody;
try
MI.Display(EmptyParam);
except
end;


if not(bOutlookRunning) then
begin
Showmessage('Please click OK when the mail has been sent.');
Outlook.Quit;
Outlook := nil;
end;
end;

andri...@gmail.com

unread,
Nov 4, 2019, 6:17:03 AM11/4/19
to
prior to outlook 2007 sending a created mail from a specific acount is to my knowledge not possible.

I'm setting the specific acount to be used using the property sendUsingAccount

account mailboxes could be read by FOutlook.Session.Accounts.Item[i]

0 new messages