Hi guys
I am having some trouble with some 8.3B code that we wrote to send an email. But only in batch mode. The code (attached below) is loaded into memory as a persistent procedure. It is a 'raw' dot-p rather than a structured procedure.
I have other code that perform various functions and call on this code to email the results to a recipients list. It is generic to the point of having input parameters to set;
1) ipc_to - a field separated list of recipients (FS for all lists is chr(28))
2) ipc_cc - a field separated list of CC recipients
3) ipc_bcc - a field separated list of BCC recipients
4) ipc_subject - the subject line text
5) ipc_message - the message body text
6) ipc_attach-file - path to an attachment file (null for no attachment)
7) ipc_file-name - the name to call the attachment (if using a TEMP file with an ugly name)
This code is starting a MS Exchange session, creating a message in the outbox and applying a handle to it, editing the message via DDE commands to the handle, sending the message and logging off the session.
I have run the code (via a calling BAT file) successfully in foreground windows sessions in both XP and NT Server with no issues whatsoever... but I cannot run it in the background. When I load the 'exact' same batch up into AT, the code seems to fall over at the line bolded (creating and applying the handle to the message). Being in batch mode... I am not getting any errors to help locate the cause either.
Any tips or help would be greatly appreciated. If you have the time to test the code in a similar environment to ours, you should only have to insert your email profile and create a calling prog.
For quickest response to any questions, please feel free to email me at c.stephenson@capilano.com.au
Regards
Craig Stephenson
IT Business Support
Capilano Honey Limited
-----------------
PROCEDURE send-mail:
def input param ipc_to as char no-undo.
def input param ipc_cc as char no-undo.
def input param ipc_bcc as char no-undo.
def input param ipc_subject as char no-undo.
def input param ipc_message as char no-undo.
def input param ipc_attach-file as char no-undo.
def input param ipc_file-name as char no-undo.
def var lc_profile as char no-undo.
def var lh_session as com-handle no-undo.
def var lh_message as com-handle no-undo.
def var lh_recip as com-handle no-undo.
def var lh_copy as com-handle no-undo.
def var lh_blind as com-handle no-undo.
def var lh_attach as com-handle no-undo.
def var li_recip as int no-undo.
lc_profile = "<<Your Email Profile>>".
create "MAPI.SESSION" lh_session.
lh_session:Logon(lc_profile, false).
lh_message = lh_session:OutBox:Messages:Add().
if not ipc_subject = ""
then lh_message:Subject = ipc_subject.
if not ipc_message = ""
then lh_message:Text = ipc_message.
if not ipc_attach-file = ""
then do:
lh_attach = lh_message:Attachments:Add().
lh_attach:Type = 1.
lh_attach
osition = length(lh_message:Text) + 1.
lh_attach:Name = ipc_file-name.
lh_attach:ReadFromFile(ipc_attach-file).
end.
lh_message:Update().
do li_recip = 1 to num-entries(ipc_to,chr(28)):
lh_recip = lh_message:Recipients:Add().
lh_recip:Name = entry(li_recip,ipc_to,chr(28)).
lh_recip:Type = 1.
lh_recip:Resolve.
end.
if not ipc_cc = ""
then
do li_recip = 1 to num-entries(ipc_cc,chr(28)):
lh_copy = lh_message:Recipients:Add().
lh_copy:Name = entry(li_recip,ipc_cc,chr(28)).
lh_copy:Type = 2.
lh_copy:Resolve.
end.
if not ipc_bcc = ""
then
do li_recip = 1 to num-entries(ipc_bcc,chr(28)):
lh_blind = lh_message:Recipients:Add().
lh_blind:Name = entry(li_recip,ipc_bcc,chr(28)).
lh_blind:Type = 3.
lh_blind:Resolve.
end.
lh_message:Update(true, true).
lh_message:Send(true, false).
lh_session:Logoff.
if valid-handle(lh_recip)
then release object lh_recip.
if valid-handle(lh_copy)
then release object lh_copy.
if valid-handle(lh_blind)
then release object lh_blind.
if valid-handle(lh_message)
then release object lh_message.
if valid-handle(lh_session)
then release object lh_session.
END PROCEDURE.
I am having some trouble with some 8.3B code that we wrote to send an email. But only in batch mode. The code (attached below) is loaded into memory as a persistent procedure. It is a 'raw' dot-p rather than a structured procedure.
I have other code that perform various functions and call on this code to email the results to a recipients list. It is generic to the point of having input parameters to set;
1) ipc_to - a field separated list of recipients (FS for all lists is chr(28))
2) ipc_cc - a field separated list of CC recipients
3) ipc_bcc - a field separated list of BCC recipients
4) ipc_subject - the subject line text
5) ipc_message - the message body text
6) ipc_attach-file - path to an attachment file (null for no attachment)
7) ipc_file-name - the name to call the attachment (if using a TEMP file with an ugly name)
This code is starting a MS Exchange session, creating a message in the outbox and applying a handle to it, editing the message via DDE commands to the handle, sending the message and logging off the session.
I have run the code (via a calling BAT file) successfully in foreground windows sessions in both XP and NT Server with no issues whatsoever... but I cannot run it in the background. When I load the 'exact' same batch up into AT, the code seems to fall over at the line bolded (creating and applying the handle to the message). Being in batch mode... I am not getting any errors to help locate the cause either.
Any tips or help would be greatly appreciated. If you have the time to test the code in a similar environment to ours, you should only have to insert your email profile and create a calling prog.
For quickest response to any questions, please feel free to email me at c.stephenson@capilano.com.au
Regards
Craig Stephenson
IT Business Support
Capilano Honey Limited
-----------------
PROCEDURE send-mail:
def input param ipc_to as char no-undo.
def input param ipc_cc as char no-undo.
def input param ipc_bcc as char no-undo.
def input param ipc_subject as char no-undo.
def input param ipc_message as char no-undo.
def input param ipc_attach-file as char no-undo.
def input param ipc_file-name as char no-undo.
def var lc_profile as char no-undo.
def var lh_session as com-handle no-undo.
def var lh_message as com-handle no-undo.
def var lh_recip as com-handle no-undo.
def var lh_copy as com-handle no-undo.
def var lh_blind as com-handle no-undo.
def var lh_attach as com-handle no-undo.
def var li_recip as int no-undo.
lc_profile = "<<Your Email Profile>>".
create "MAPI.SESSION" lh_session.
lh_session:Logon(lc_profile, false).
lh_message = lh_session:OutBox:Messages:Add().
if not ipc_subject = ""
then lh_message:Subject = ipc_subject.
if not ipc_message = ""
then lh_message:Text = ipc_message.
if not ipc_attach-file = ""
then do:
lh_attach = lh_message:Attachments:Add().
lh_attach:Type = 1.
lh_attach

lh_attach:Name = ipc_file-name.
lh_attach:ReadFromFile(ipc_attach-file).
end.
lh_message:Update().
do li_recip = 1 to num-entries(ipc_to,chr(28)):
lh_recip = lh_message:Recipients:Add().
lh_recip:Name = entry(li_recip,ipc_to,chr(28)).
lh_recip:Type = 1.
lh_recip:Resolve.
end.
if not ipc_cc = ""
then
do li_recip = 1 to num-entries(ipc_cc,chr(28)):
lh_copy = lh_message:Recipients:Add().
lh_copy:Name = entry(li_recip,ipc_cc,chr(28)).
lh_copy:Type = 2.
lh_copy:Resolve.
end.
if not ipc_bcc = ""
then
do li_recip = 1 to num-entries(ipc_bcc,chr(28)):
lh_blind = lh_message:Recipients:Add().
lh_blind:Name = entry(li_recip,ipc_bcc,chr(28)).
lh_blind:Type = 3.
lh_blind:Resolve.
end.
lh_message:Update(true, true).
lh_message:Send(true, false).
lh_session:Logoff.
if valid-handle(lh_recip)
then release object lh_recip.
if valid-handle(lh_copy)
then release object lh_copy.
if valid-handle(lh_blind)
then release object lh_blind.
if valid-handle(lh_message)
then release object lh_message.
if valid-handle(lh_session)
then release object lh_session.
END PROCEDURE.