none
Outlook attachment file name takes on metadata description when message format is HTML but not for RTF format RRS feed

  • Question

  • 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 script Outlook to use the name in the metadata description field for Rich Text messages where HTML formatted messages do this by default?

    So to clarify - We are sending a document from Eclipse through e-mail.  The document we are sending has some metadata on it called a description.  In the screenshot below it shows test.

    the actual file name being attached is c:\uses\xxxxx\documents\135000003311.pdf and in a RTF message displays in the message body using the file name

    If we choose HTML message format - the attached file name uses the name in the description field (test) - I couldn't upload my screen shots



            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
    


    Thursday, March 28, 2019 9:20 PM

Answers

  • Thank You - I was going to post it here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/newthread?category=vslanguages&forum=vbgeneral

    but let me know where you post it and I will hold off on posting it.  Thank you so much for your help.  I support Outlook but I am working with a programmer who is writing this code. I will mark this as answered

    Friday, March 29, 2019 1:51 PM

All replies

  • Here is the code being used with the Yellow highlighted section dealing with the attachments

            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

    Thursday, March 28, 2019 9:23 PM
  • Please do not post colorized code.  You must post code with the code posting tool provided on the edit bar.  Please edit your post and fix this.


    \_(ツ)_/

    Thursday, March 28, 2019 10:40 PM
  • Note also that this forum does not support third party script implementations.  You will need to post to the vendors forum.

    The code posted is VBA and not VBScript.  This is not a VBA forum.


    \_(ツ)_/


    • Edited by jrv Thursday, March 28, 2019 10:42 PM
    Thursday, March 28, 2019 10:41 PM
  •         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
    

    Friday, March 29, 2019 12:57 PM
  • Once again. This is not a VBA or VB forum.  Your code is not a script.  This forum is for administrative scripting with WSH (vbscript/jscript) and PowerShell.


    \_(ツ)_/

    Friday, March 29, 2019 1:36 PM
  • Someone will move this to the VBA forum.  The code you have is a bad mix of VBA, VB6 and VB.Net.  How you would do this depends on the system being used to host the code.

    If using Outlook then most of your code is unnecessary.  Outlook can do all of this with no issues and does not require declaring pointers or handlers.

    If you are using VB.Net then most of this is also unnecessary. 

    "CodeField" seems to have gone out of business.  Perhaps you have a support number.  Contact them for help with the attachments.


    \_(ツ)_/


    • Edited by jrv Friday, March 29, 2019 1:56 PM
    Friday, March 29, 2019 1:44 PM
  • Thank You - I was going to post it here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/newthread?category=vslanguages&forum=vbgeneral

    but let me know where you post it and I will hold off on posting it.  Thank you so much for your help.  I support Outlook but I am working with a programmer who is writing this code. I will mark this as answered

    Friday, March 29, 2019 1:51 PM
  • If you want to post the link to the VBA forum I should use - I can post my question
    Friday, March 29, 2019 2:13 PM
  • If you want to post the link to the VBA forum I should use - I can post my question

    Are you doing this in Outlook VBA?


    \_(ツ)_/

    Friday, March 29, 2019 2:21 PM
  • Friday, March 29, 2019 2:22 PM
  • My programmer said the code is VB.net not VBA so I posted my question here:

    https://social.msdn.microsoft.com/Forums/en-US/0eaded3e-b104-43b5-8bd6-3c6350d676af/attachment-file-name-takes-on-metadata-description-when-message-format-is-html-but-not-for-rtf?forum=vbgeneral

    Friday, March 29, 2019 2:36 PM