K
Karen Fed IT Specialist
Guest
We send documents from our in-house Eclipse system that uses VB script to open a new email with message format of Rich text. When attaching files we add some metadata called a description which is the name we want the attachment to display in the email but instead it displays the actual file name. If we use the HTML message format, the attached file will take on the name set in the description field. We don't want to use the HTML message format because it does not allow the attachments to be positioned instream and context placed around it. How can we code so the name of the attached file in the Outlook RTF message format uses the metadata description field for the name instead of the actual file name? HTML formatted messages do this by default - they use the value in the Description field.
So to clarify - We are sending a document from Eclipse using Outlook as the email client. The document has some metadata on it called a description which contains the value "test"
The document being attached has the file name C:\Users\XXXXXX\AppData\Roaming\Documents\Cache\000002001\135000003311.PDF.
We default the outlook message to format RTF and the name of the attachment displays as the file name "135000003311.PDF"
If we choose the HTML message format – the attached file name automatically changes to the name in the description field "test"
The section dealing with the attachments starts here: If Not anAttachmentList Is Nothing Then
Public Sub launchMailItem(ByVal aToList As StringCollection _
, ByVal anAttachmentList As CodeFieldList _
, ByVal anIsFax As Boolean _
, ByVal aSubjectLineText As String _
, ByVal aSignaturePath As String _
, ByVal anEmailReporting As EmailReporting)
coverLetterFileName = String.Empty
emailReporter = anEmailReporting
messageSent = False
Try
emailItem = CType(outlookApplication.CreateItem(Outlook.OlItemType.olMailItem), _
Outlook.MailItem)
AddHandler emailItem.Send _
, AddressOf handleEmailItemSend
AddHandler emailItem.Close _
, AddressOf handleEmailItemClose
emailItem.SentOnBehalfOfName = _
SessionManager.commonMailBoxName
emailItem.Subject = aSubjectLineText
'default the email to Rich Text format
emailItem.BodyFormat = Outlook.OlBodyFormat.olFormatRichText
If Not anAttachmentList Is Nothing Then
Dim myDisplayName As String
For Each myAttachment As CodeField In anAttachmentList
myDisplayName = CodeField.getDescriptionString(myAttachment)
If myDisplayName = String.Empty AndAlso _
System.IO.File.Exists(CodeField.getCodeString(myAttachment)) Then
myDisplayName = _
System.IO.Path.GetFileName(CodeField.getCodeString(myAttachment))
End If
emailItem.Attachments.Add(CodeField.getCodeString(myAttachment) _
, _
, 1 _
, myDisplayName)
Next
End If
Me.checkOutlook(emailItem)
If outlookApplication.Session.Offline OrElse
Not Me.isOutlookOpen Then
Throw New EclipseWarningException _
("Outlook is currently offline; Eclipse cannot successfully send mail when outlook is offline. Please make sure Outlook is open and connected.", _
Nothing)
End If
If Not Me.isDefaultSignatureExists Then
Throw New EclipseWarningException _
("A default signature was not found. Please set a default signature in Outlook and try again.", _
Nothing)
End If
If Not String.IsNullOrEmpty(aSignaturePath) Then
''if they have a default signature set we will delete if first
DeleteSignature(emailItem)
' ''add the signature to the email
InsertSignature(emailItem, aSignaturePath)
End If
If aToList IsNot Nothing Then
Dim myToString As New StringBuilder
For Each mystring As String In aToList
myToString.Append(";" & mystring)
Next
If myToString.Length > 0 Then
'remove the first ";"
myToString.Remove(0, 1)
End If
emailItem.To = myToString.ToString
End If
postitionEmailCursor(emailItem)
emailItem.Display()
'We will capture whenever an email is saved. It is added after the emailItem.Display statement because
'the initial opening of the email throws a write event which we will skip.
AddHandler emailItem.Write _
, AddressOf handleEmailItemSave
Catch ew As EclipseWarningException
Throw ew
Catch ex As Exception
Throw New OutlookLaunchException(ex)
End Try
End Sub
Continue reading...
So to clarify - We are sending a document from Eclipse using Outlook as the email client. The document has some metadata on it called a description which contains the value "test"
The document being attached has the file name C:\Users\XXXXXX\AppData\Roaming\Documents\Cache\000002001\135000003311.PDF.
We default the outlook message to format RTF and the name of the attachment displays as the file name "135000003311.PDF"
If we choose the HTML message format – the attached file name automatically changes to the name in the description field "test"
The section dealing with the attachments starts here: If Not anAttachmentList Is Nothing Then
Public Sub launchMailItem(ByVal aToList As StringCollection _
, ByVal anAttachmentList As CodeFieldList _
, ByVal anIsFax As Boolean _
, ByVal aSubjectLineText As String _
, ByVal aSignaturePath As String _
, ByVal anEmailReporting As EmailReporting)
coverLetterFileName = String.Empty
emailReporter = anEmailReporting
messageSent = False
Try
emailItem = CType(outlookApplication.CreateItem(Outlook.OlItemType.olMailItem), _
Outlook.MailItem)
AddHandler emailItem.Send _
, AddressOf handleEmailItemSend
AddHandler emailItem.Close _
, AddressOf handleEmailItemClose
emailItem.SentOnBehalfOfName = _
SessionManager.commonMailBoxName
emailItem.Subject = aSubjectLineText
'default the email to Rich Text format
emailItem.BodyFormat = Outlook.OlBodyFormat.olFormatRichText
If Not anAttachmentList Is Nothing Then
Dim myDisplayName As String
For Each myAttachment As CodeField In anAttachmentList
myDisplayName = CodeField.getDescriptionString(myAttachment)
If myDisplayName = String.Empty AndAlso _
System.IO.File.Exists(CodeField.getCodeString(myAttachment)) Then
myDisplayName = _
System.IO.Path.GetFileName(CodeField.getCodeString(myAttachment))
End If
emailItem.Attachments.Add(CodeField.getCodeString(myAttachment) _
, _
, 1 _
, myDisplayName)
Next
End If
Me.checkOutlook(emailItem)
If outlookApplication.Session.Offline OrElse
Not Me.isOutlookOpen Then
Throw New EclipseWarningException _
("Outlook is currently offline; Eclipse cannot successfully send mail when outlook is offline. Please make sure Outlook is open and connected.", _
Nothing)
End If
If Not Me.isDefaultSignatureExists Then
Throw New EclipseWarningException _
("A default signature was not found. Please set a default signature in Outlook and try again.", _
Nothing)
End If
If Not String.IsNullOrEmpty(aSignaturePath) Then
''if they have a default signature set we will delete if first
DeleteSignature(emailItem)
' ''add the signature to the email
InsertSignature(emailItem, aSignaturePath)
End If
If aToList IsNot Nothing Then
Dim myToString As New StringBuilder
For Each mystring As String In aToList
myToString.Append(";" & mystring)
Next
If myToString.Length > 0 Then
'remove the first ";"
myToString.Remove(0, 1)
End If
emailItem.To = myToString.ToString
End If
postitionEmailCursor(emailItem)
emailItem.Display()
'We will capture whenever an email is saved. It is added after the emailItem.Display statement because
'the initial opening of the email throws a write event which we will skip.
AddHandler emailItem.Write _
, AddressOf handleEmailItemSave
Catch ew As EclipseWarningException
Throw ew
Catch ex As Exception
Throw New OutlookLaunchException(ex)
End Try
End Sub
Continue reading...