Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

e-mail via Impromptu Macro 2

Status
Not open for further replies.

ADB1

Programmer
Aug 24, 2001
235
GB
All,

We are trying to generate automatic emails via a macro in Impromptu, and send out a pdf as an attachment. At the moment we can't schedule these mails due to the fact that outlook sits waiting for a response to a message window stating that a program is trying to send a mail on 'your' behalf, do you wish to allow this, Yes/No.

Has anybody else had to overcome this problem or suggest a way around it. We cannot turn the message off due to company policy and security.

Any suggestions would be greatly appreciated.

Regards,

Adam.
 
Adam,

Here's a sub-routine I use to send via Outlook.

Hope it helps you.

Regards,

Dave Griffin :)

Declare Sub SendMes(strRcp as String,strFilePath As String, strSalutation as String, strCustYYMM as String)

Sub Main()

Dim objPPApp As Object
Dim objPPRep As Object
Dim ReportPath$, Salutation$, CustYYMM$
Dim ImpApp As Object
Dim ImpRep As Object

On Error Goto ErrorHandler

Recipient = "SMTP or Exchange Name Here"
ReportPath = "Report file (PDF or Other) and Path here"
Salutation = "First Name Here"
CustYYMM$ = "139910"


Call SendMes(Recipient,ReportPath,Salutation,CustYYMM)

Set objTask = Nothing
Set objSchedApp = Nothing

'Finish the routine
'------------------
Finish:
Exit Sub

ErrorHandler:
MsgBox("Error: "+Error$)
'MsgBox("Error: "+CPApp.GetErrorNumber)
resume Finish


End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub SendMes(strRcp as String,strFilePath As String, strSalutation as String, strCustYYMM as String)


Dim objOutlook As Object
Dim objMail As Object
Dim objOutlookAttach As Object
Dim arrFileList() as String
Dim i as Integer
Dim strBodyMess as String

redim arrFileList(4)
i = 1

strBodyMess = "Hi "+strSalutation+","+Chr$(13)+Chr$(13)
strBodyMess = strBodyMess+"Your Invoice Files are attached "+Chr$(13)+Chr$(13)
strBodyMess = strBodyMess+"Files prepared and send via CognosScript(tm) Macro"+Chr$(13)+Chr$(13)


arrFileList(1) = strFilePath+"\"+strCustYYMM+"IV.PDF"
arrFileList(2) = strFilePath+"\"+strCustYYMM+"LB.PDF"
arrFileList(3) = strFilePath+"\"+strCustYYMM+"OD.PDF"


Set objOutlook = CreateObject("OutLook.Application")
Set objMail = objOutlook.CreateItem(olMailItem) 'Create a new

Set objOutlookAttach = objOutlook.CreateItem(olAttachMents)


With objMail
.To = strRcp
.Subject = "Your Monthly Invoice & Supporting Files" 'Subjectline of message
'.Body = "Hi " & strSalutation & "," & Chr$(13) & Chr$(13) & "Your Invoice Files are attached "
.Body = strBodyMess

for i = 1 to 3
.Attachments.Add(arrFileList(i))
next i

.Send 'Send the message

End With
Set objMail = Nothing
Set objOutlook = Nothing




End Sub
 
Griff,

This was an excellant stuff.However when I tried this outlook is asking like the below


A Program is trying to automatically send an email on your behalf.Do you want to allow this?


Is is possble to avoid this and send the message automatically?


Regards
Senthil
 
Senthil,
With current versions of MS Outlook, it is not possible to avoid it, as it is part of the security (anti-virus) features of outlook. In the future, it may be that Cognos is a trusted sign-on to Outlook so that macros can run unattended.
Until then, there would be two solutions, each with their own attendent problems.
1) Downgrade Outlook to an earlier version.
2) Use SMTP to send mail to your company's outlook server. This obviously requires SMTP to be installed and correctly configured on the PC. I have posted macro code that calls CDONT email earlier this year on a similar thread.

HTH
lex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top