BusinessObjects Board

sending email from bca

l have this report in bca that is creating the pdf file and everything else, but l can’t make it send emails. l have included the correct smtp information and l also have a simple smtp application which l used to test the smtp server and it is working just fine and sending me emails, but not the bca report. Thanks,

Public Sub SendEmail()

Dim ObjMessage As CDO.Message
Dim Cfg As CDO.Configuration
Dim doc As Document
Dim docname, tempdoc As String
Dim Rep As REPORT
Dim i As Integer

Set doc = ActiveDocument
doc.Refresh
doc.Save
docname = doc.FullName
tempdoc = doc.Name & format(Now, "MM-DD-YYYY hh\hmm")
doc.SaveAs (tempdoc)

For i = 1 To doc.Reports.Count
Set Rep = doc.Reports.Item(i)
Rep.ExportAsPDF ("C:\Reports\" & Rep.Name)
Next i
On Error Resume Next

Set ObjMessage = New CDO.Message

If Err.Number <> 0 Then WriteError (Now &amp; " " &amp; Err.Description)


'establish server settings
Set Cfg = New CDO.Configuration
Cfg.Fields(cdoSendUsingMethod) = 25
Cfg.Fields(cdoSMTPServer) = "mysmtp host"
Cfg.Fields.Update


ObjMessage.TextBody = "Text in e-mail!"
ObjMessage.subject = "text subject in e-mail"
ObjMessage.From = "my email"
ObjMessage.To = "my email"

On Error Resume Next
For i = 1 To doc.Reports.Count

ObjMessage.AddAttachment ("C:\Reports\" &amp; Rep.Name &amp; ".pdf")

If Err.Number <> 0 Then
WriteError (Now &amp; " " &amp; Err.Description)
Else
WriteError (Now &amp; " " &amp; "C:\Reports\" &amp; Rep.Name &amp; ".pdf" &amp; " Added")
End If

Next i

On Error Resume Next
ObjMessage.Send

If Err.Number <> 0 Then
WriteError (Now &amp; " " &amp; Err.Description)
Else
WriteError (Now &amp; " Message sent")
End If
On Error Resume Next

Kill tempdoc

If Err.Number <> 0 Then
WriteError (Now &amp; " " &amp; Err.Description)
Else
WriteError (Now &amp; " " &amp; tempdoc &amp; " deleted")
End If

End Sub

Public Sub WriteError(Err_Description As String)
'The error_text.txt file where the messages and potential error
'message are going to be saved.
Open "C:\error_text.txt" For Append As #1
'Print #1, Err_Description
Close #1
End Sub

[When posting code samples please use the code option for formatting. It will preserve any indenting or formatting that you may have done. Thank you, Andreas]


abieyuwae (BOB member since 2004-06-07)

This FAQ has a link to an existing script that uses CDO - it might be worth a look to see if you can spot a relevant difference between it and your script.


Nick Daniels :uk: (BOB member since 2002-08-15)