Skip to main content
March 5, 2024
Solved

Attaching file to the Mail

  • March 5, 2024
  • 2 replies
  • 0 views

Hi,

Is it possible to attach a file from the public folder to the mail using the function,

BRApi.Utilities.SendMail(si, emailConnectionName, toEmailAddresses, subject, body, attachmentFilePaths)

Would appreciate any assistance.

Thank You.

Best answer by sameburn

Hi Shivangi. This is expected behaviour. The SendEmail BRApi is expecting the file path to be a real file path e.g represented by Fileshare on your server(s). Whereas the Application file path is stored in the database. So not a real file path per se. 

So the solution (as you have already discovered) is to use file paths that refer to Fileshare file paths and everything works as expected.

Hope this helps.

Sam

2 replies

March 5, 2024

Hi Shivangi  Here's an extender sample to help get you started

Namespace OneStream.BusinessRule.Extender.SendMail
    Public Class MainClass
        Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As ExtenderArgs) As Object
            Try
                Dim fileFullName As String = "EmailAttachment.png"
                Dim failGracefully As Boolean = True
                Dim includeContentFileBytes As Boolean = True
                Dim objXFFileEx As XFFileEx = BRApi.FileSystem.GetFile(si, FileSystemLocation.ApplicationDatabase, fileFullName, includeContentFileBytes, failGracefully)
                Dim fullNamePath As String = objXFFileEx.XFFile.FileInfo.FullName
                Dim attachmentFilePaths As List(Of String) = New List(Of String)() From {
                    fullNamePath
                }
                 Return Nothing
            Catch ex As Exception
                Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
            End Try
        End Function
    End Class
End Namespace

 

ShivangiAuthor
March 6, 2024

Hi, Thank You for providing the snippet. I tried this way to attach my file, I was getting the File path as well but when I pass the filepath in the BRApi.Utilities.SendMail(...) function I was getting an error.

Could not find a part of the path 'C:\Program Files\OneStream Software\OneStreamAppRoot\OneStreamApp\Documents\Public\File.csv

 
Code:
Dim failGracefully As Boolean = True
Dim includeContentFileBytes As Boolean = True
Dim objXFFileEx As XFFileEx = BRApi.FileSystem.GetFile(si, FileSystemLocation.ApplicationDatabase, "Documents\Public\File.csv", includeContentFileBytes, failGracefully)
Dim fullNamePath As String = objXFFileEx.XFFile.FileInfo.FullName
Dim attachmentFilePaths As List(Of String) = New List(Of String)() From {
                    fullNamePath
                }
BRApi.Utilities.SendMail(si, emailConnectionName, toEmail, subject, Msg, True, attachmentFilePaths)
 
March 6, 2024

Based on the code you posted, this error is not possible.  Its coming from somewhere else.
Using your code...

Dim failGracefully As Boolean = True
Dim includeContentFileBytes As Boolean = True
Dim objXFFileEx As XFFileEx = BRApi.FileSystem.GetFile(si, FileSystemLocation.ApplicationDatabase, "Documents\Public\File.csv", includeContentFileBytes, failGracefully)
Dim fullNamePath As String = objXFFileEx.XFFile.FileInfo.FullName

BRApi.ErrorLog.LogMessage(si, fullNamePath) 'gives "Documents/Public/File.csv" in the error log.

 

sameburnAnswer
December 5, 2024

Hi Shivangi. This is expected behaviour. The SendEmail BRApi is expecting the file path to be a real file path e.g represented by Fileshare on your server(s). Whereas the Application file path is stored in the database. So not a real file path per se. 

So the solution (as you have already discovered) is to use file paths that refer to Fileshare file paths and everything works as expected.

Hope this helps.

Sam