Hi Jon,
Here is some code that I think should work. I haven't tested it but it is modified from some code I do use. There are a couple of optional bits in there which I have commented with OPTIONAL
OLEObject ole_item, ole_attach, ole_outlook
integer li_result
String ls_folderfile, ls_email_addr, ls_subject, ls_email_text_message
//Do you need the sender's email address?
String ls_sender_addr
integer li_return = 1
ls_folderfile = "c:\pdf\pbreport.pdf"
idw_rpt.Object.DataWindow.Export.PDF.Method = XSLFOP!
li_return = idw_rpt.SaveAs(ls_folderfile, PDF!, true)
// The SaveAs failed so handle it. I'm just returning early for this example
if li_return < 1 then return -1
ls_sender_addr = "jon@akaware.com"
ls_email_addr = "jonstoller56@gmail.com"
ls_subject = "Report from AKA Software"
ls_email_text_message = "The attachment is a report from AKA Software"
ole_outlook = Create OLEObject
//Connect to Outlook session using 'Outlook.Application'
li_result = ole_outlook.ConnectToNewObject("outlook.application")
if li_result <> 0 then
// ERROR CONDITION
Messagebox("Outlook Error","Could not launch Outlook.~n~rReturn Code [" + string(li_result) + "]")
destroy ole_outlook
li_return = -1
else
// Creates a new mail Item
ole_item = ole_outlook.CreateItem(0)
// OPTIONAL - If you don't fill this in then it will just use the default email from account
ole_item.SentOnBehalfOfName = ls_sender_addr
// Set the recipient
ole_item.To = ls_email_addr
// OPTIONAL - Set the CC
ole_item.Cc = 'cc@madeup.domain.com'
// Set the subject line of message
ole_item.Subject = ls_subject
// Body of mail message
ole_item.Body = ls_email_text_message + char(13)
// OPTIONAL - if you want to use HTML in the body
//ole_item.BodyFormat = 2 // olFormatHTML
//ole_item.HTMLBody = ls_email_text_message + char(13)
try
ole_attach = ole_item.Attachments
ole_attach.Add(ls_folderfile)
catch (throwable t2)
MessageBox('Error Adding Attachments', "There was an error adding attachments to Outlook. The attachment size may exceed Outlook's allowable limit.", StopSign!)
li_return = -1
end try
if li_return = 1 then
ole_item.Display // Displays the message
try
ole_item.Send
catch (throwable t)
// Swallow this exception. Can occur if the user cancels the email (e.g. after being presented with blank subject warning message)
li_return = -1
end try
end if
ole_outlook.DisconnectObject()
destroy ole_outlook
end if
return li_return
I want to know that i created this application in which i made the report in which all mangers can see the report and save it on pdf.
can i set above email setup on the background that in morning 10am it will auto send to managers.
You could use the Outlook code but it is probably not really meant for unattended tasks because it could block if a messagebox is displayed from Outlook. For unattended emailing we use a .Net email object we wrote in C# via COM interop in Powerbuilder so it is a totally non-visual object. I think you could do something similar using Bruce Armstrong's PBNISmtp object.
I will try it.
Jon Stoller