Hi Reece,
If you want to attach PDF or XLS files you can use the following script which also saves the email in the sent box. The earlier scripts I used didn't do that which is a problem when logging email distribution.
See what you think.
Craig Nichols
Declare Sub SendNotesMail(Attachment As String, Recipient As String, BodyText As String, Subject As String)
Declare Sub GenerateReports(strIMRReportPath As String, strIMRReportName As String, strReportPath As String, strReportName As String, strPDFSwitch as String, strExcelSwitch as String, strPrintSwitch as String)
Sub Main()
Dim ImpApp as Object
Dim ImpRep as Object
Dim PDFPub as Object
Dim objPDF as Object
Dim strIMRReportPath
Dim strIMRReportName
Dim strReportPath
Dim strReportName
Dim strPDFSwitch
Dim strExcelSwitch
Dim strPrintSwitch
Dim BodyText
Dim Recipient
Dim Attachment
Dim Subject
' REPORT NAME'
' P&N ORDERS LESS THAN $100 '
strIMRReportPath = "J:\BI\Reports\PAN\MANAGEMENT REPORTS\"
strIMRReportName = "P&N ORDERS LESS THAN $100"
strReportPath = "U:\COGNOS REPORTS\MANAGEMENT\"
strReportName = Mid$(Date$,7,4) + Mid$(Date$,1,2) + Mid$(Date$,4,2) & " " & strIMRReportName
strPDFSwitch = "Y"
strExcelSwitch ="Y"
strPrintSwitch = "Y"
Call GenerateReports(strIMRReportPath, strIMRReportName, strReportPath, strReportName, strPDFSwitch, strExcelSwitch, strPrintSwitch)
'EMAIL ADOBE REPORT'
Recipient = "MONTHLYMANAGEMENT"
BodyText = strReportName
Attachment = strReportPath + BodyText + ".pdf"
Subject = strReportName
Call SendNotesMail(Attachment, Recipient, BodyText, Subject )
' REPORT NAME'
' OUTSTANDING SPECIAL SALES '
strIMRReportPath = "J:\BI\Reports\PAN\MANAGEMENT REPORTS\"
strIMRReportName = "OUTSTANDING SPECIAL SALES"
strReportPath = "U:\COGNOS REPORTS\MANAGEMENT\"
strReportName = Mid$(Date$,7,4) + Mid$(Date$,1,2) + Mid$(Date$,4,2) & " " & strIMRReportName
strPDFSwitch = "N"
strExcelSwitch ="Y"
strPrintSwitch = "N"
Call GenerateReports(strIMRReportPath, strIMRReportName, strReportPath, strReportName, strPDFSwitch, strExcelSwitch, strPrintSwitch)
'EMAIL ADOBE REPORT'
Recipient = "MONTHLYSPECIALS"
BodyText = strReportName
Attachment = strReportPath + BodyText + ".pdf"
Subject = strReportName
Call SendNotesMail(Attachment, Recipient, BodyText, Subject )
' REPORT NAME'
' PN8006M GRINDING WHEEL USAGE MAR '
strIMRReportPath = "J:\BI\Reports\PAN\MANAGEMENT REPORTS\"
strIMRReportName = "PN8006M GRINDING WHEEL USAGE MAR"
strReportPath = "U:\COGNOS REPORTS\MANAGEMENT\"
strReportName = Mid$(Date$,7,4) + Mid$(Date$,1,2) + Mid$(Date$,4,2) & " " & strIMRReportName
strPDFSwitch = "N"
strExcelSwitch ="Y"
strPrintSwitch = "N"
Call GenerateReports(strIMRReportPath, strIMRReportName, strReportPath, strReportName, strPDFSwitch, strExcelSwitch, strPrintSwitch)
'EMAIL ADOBE REPORT'
Recipient = "thudson@pnaust.com.au"
BodyText = strReportName
Attachment = strReportPath + BodyText + ".pdf"
Subject = strReportName
Call SendNotesMail(Attachment, Recipient, BodyText, Subject )
' REPORT NAME'
' P&N CREDITS OSBSTD '
strIMRReportPath = "J:\BI\Reports\PAN\MANAGEMENT REPORTS\"
strIMRReportName = "P&N CREDITS OSBSTD"
strReportPath = "U:\COGNOS REPORTS\MANAGEMENT\"
strReportName = Mid$(Date$,7,4) + Mid$(Date$,1,2) + Mid$(Date$,4,2) & " " & strIMRReportName
strPDFSwitch = "Y"
strExcelSwitch ="N"
strPrintSwitch = "N"
Call GenerateReports(strIMRReportPath, strIMRReportName, strReportPath, strReportName, strPDFSwitch, strExcelSwitch, strPrintSwitch)
'EMAIL ADOBE REPORT'
Recipient = "MONTHLYMANAGEMENT"
BodyText = strReportName
Attachment = strReportPath + BodyText + ".XLS"
Subject = strReportName
Call SendNotesMail(Attachment, Recipient, BodyText, Subject )
End Sub
' *** Sub to Generate ReportS in Adobe and Excel with Format ***
Sub GenerateReportS(strIMRReportPath As String, strIMRReportName As String, strReportPath As String, strReportName As String, strPDFSwitch as String, strExcelSwitch as String, strPrintSwitch as String)
Dim ImpApp as Object
Dim ImpRep as Object
Dim PDFPub as Object
Set ImpApp = CreateObject("Impromptu.Application"

ImpApp.Visible True
Set ImpRep = ImpApp.OpenReportNoExecute(strIMRReportPath + strIMRReportName + ".imr"

ImpRep.Reexecute
'ADOBE EXPORT'
if strPDFSwitch= "Y" then Set PDFPub = ImpRep.PublishPDF
if strPDFSwitch= "Y" then PDFPub.Publish strReportPath & strReportName & ".PDF"
'PRINT REPORT'
if strPrintSwitch = "Y" then ImpRep.Print
'EXCEL WITH FORMAT EXPORT'
if strExcelSwitch = "Y" then AppActivate "Impromptu - [" & strIMRReportName & ".imr]"
if strExcelSwitch = "Y" then SendKeys "%F",1
if strExcelSwitch = "Y" then SendKeys "A",1
if strExcelSwitch = "Y" then SendKeys "{TAB}",1
if strExcelSwitch = "Y" then SendKeys "{DOWN 8}",1
if strExcelSwitch = "Y" then SendKeys "{ENTER}",1
if strExcelSwitch = "Y" then SendKeys "+{TAB}",1
if strExcelSwitch = "Y" then SendKeys strReportPath & strReportName & ".XLS",1
if strExcelSwitch = "Y" then SendKeys "{ENTER}",1
'CLOSE REPORT
ImpRep.CloseReport
'CLOSE IMPROMTU'
ImpApp.Quit
Set objImpRep = Nothing
Set objImpApp = Nothing
Set objPDFPub = Nothing
End Sub
' *** Subroutine to Send Email and Attachment ***
Sub SendNotesMail(Attachment As String, Recipient As String, BodyText As String, Subject As String)
'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
'Start a session to notes
Set Session = CreateObject("Notes.NotesSession"

'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
UserName = Session.UserName
MailDbName = "COGNOS.nsf"
'Open the mail database in notes
Set Maildb = Session.GETDATABASE("", MailDbName)
If Maildb.ISOPEN = True Then
'Already open for mail
Else
Maildb.OPENMAIL
End If
'Set up the new mail document
Set MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = "Memo"
MailDoc.sendto = Recipient
MailDoc.Subject = Subject
MailDoc.Body = "REFER ATTACHMENTS *** This email has been automatically generated from the P&N Cognos Reporting System ***"
MailDoc.SAVEMESSAGEONSEND = True
'Set up the embedded object and attachment and attach it
If Attachment <> "" Then
Set AttachME = MailDoc.CREATERICHTEXTITEM("Attachment"

Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", Attachment)
MailDoc.CREATERICHTEXTITEM ("Attachment"
End If
'Send the document
MailDoc.PostedDate = Now()
'Gets the mail to appear in the sent items folder
MailDoc.SEND 0, Recipient
'Clean Up
Set Maildb = Nothing
Set MailDoc = Nothing
Set AttachME = Nothing
Set Session = Nothing
Set EmbedObj = Nothing
End Sub