Results 1 to 7 of 7

Thread: Outlook signatures created via VB6 won't show images.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2015
    Location
    Cambridge, UK
    Posts
    9

    Outlook signatures created via VB6 won't show images.

    I have created a small application, using RobDogg88's example, to create e-mails automatically, when needed.
    I have tried without success to get the correct signature appended.
    The signature itself appends OK, but the three images don't show up, just leaving a place-holder and the message "This image cannot currently be displayed."
    Code:
                    .HTMLBody = .HTMLBody & "Please contact me, by e-mail or Skype, if you have any difficulties with this.<BR/><BR/>"
                    .HTMLBody = .HTMLBody & "</p>"
                    .HTMLBody = .HTMLBody & "</pre>"
                    Sig_Dir = Environ("APPDATA") & "\Microsoft\Signatures\"
                    Set oFSO = CreateObject("Scripting.FileSystemObject")
                    Set oTextStream = oFSO.OpenTextFile(Sig_Dir & "New_Teqhou.htm")
                    Signature = oTextStream.ReadAll
                    .HTMLBody = .HTMLBody & Signature
                    .Importance = olImportanceHigh
                    .ReadReceiptRequested = False
                    .Display  'Show the email message and allow for editing before sending
    This is what the result shows as:
    Name:  New Bitmap Image.png
Views: 1291
Size:  6.4 KB


    I also tried reading the signature and editing it to add full paths for the relevant images, but no difference:

    Code:
        Private Function ReadSignature(sigName As String) As String
        Sig_Dir = Environ("APPDATA") & "\Microsoft\Signatures\"
        Set oFSO = CreateObject("Scripting.FileSystemObject")
        Set oTextStream = oFSO.OpenTextFile(Sig_Dir & sigName)
        Signature = oTextStream.ReadAll
        HTM_Dir = Replace(sigName, ".htm", "_files\")
        Signature = Replace(Signature, sigName, Sig_Dir & HTM_Dir)
        Signature = Replace(Signature, "Teqhou_logo.jpg", Sig_Dir & "/Teqhou_logo.jpg")
        Signature = Replace(Signature, "MS_Partners.jpg", Sig_Dir & "/MS_Partners.jpg")
        Signature = Replace(Signature, "MS_Dynamics.jpg", Sig_Dir & "/MS_Dynamics.jpg")
        Signature = Replace(Signature, "New_Teqhou_Files/image002.png", Sig_Dir & HTM_Dir & "/image002.png")
        Signature = Replace(Signature, "New_Teqhou_Files/image003.png", Sig_Dir & HTM_Dir & "/image003.png")
        Signature = Replace(Signature, "New_Teqhou_Files/image004.png", Sig_Dir & HTM_Dir & "/image004.png")
        Dim temphtm As Integer
        temphtm = FreeFile
        Open Sig_Dir & "Test.htm" For Output As temphtm
        Print #temphtm, Signature
        Close temphtm
        ReadSignature = Signature
    End Function
    I've tried saving "signature" as a separate .htm file , but that confuses me more! If I double-click that file, the e-mail opens with all images intact!

    Anyone have any idea where I'm going wrong?

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,845

    Re: Outlook signatures created via VB6 won't show images.

    The actual image has to be embedded in the HTMLbody and should not be a reference.

    Have a look at this page for a sample:
    http://www.rondebruin.nl/win/s1/outlook/signature.htm

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2015
    Location
    Cambridge, UK
    Posts
    9

    Re: Outlook signatures created via VB6 won't show images.

    Quote Originally Posted by Arnoutdv View Post
    The actual image has to be embedded in the HTMLbody and should not be a reference.

    Have a look at this page for a sample:
    http://www.rondebruin.nl/win/s1/outlook/signature.htm
    Thanks, I tried that, but no change!

    Here's my updated code:

    Code:
        Dim strbody As String
        Dim SigString As String
        Dim Signature As String
        SigString = Environ("appdata") & "\Microsoft\Signatures\New_Teqhou.htm"
        If Dir(SigString) <> "" Then
            Signature = GetBoiler(SigString)
        Else
            Signature = ""
        End If
    
    '"About 20 lines of code that build the body text for the message are here, starting:
    
                strbody = "<font face=Verdana> Dear " & oUser.FirstName & ",</font><BR/><BR/>"
                strbody = strbody & "Your AD password, which controls access to Teqhou servers, e-mail, etc., runs for a maximum of <font color=red>" & dblMaxPwdDays & " days.</font><BR/><BR/>"
    
    etc.
    
                strbody = strbody & "Please contact me, by e-mail or Skype, if you have any difficulties with this.<BR/><BR/>"
                strbody = strbody & "</p>"
                strbody = strbody & "</pre>"
                Set oApp = CreateObject("Outlook.Application")
                Set oEmail = oApp.CreateItem(olMailItem)
                With oEmail
                    .BodyFormat = olFormatHTML
                    .Recipients.Add (oUser.get("mail"))
                    .Subject = "Network Password Expiration Notice"
                    .HTMLBody = strbody & "<br>" & Signature
                    .Importance = olImportanceHigh
                    .ReadReceiptRequested = False
                    .Display  'Show the email message and allow for editing before sending
                End With
                Set oEmail = Nothing
            End If
            Set whenpasswordexpires = Nothing
            Set oApp = Nothing
    next_rs:
            rs.MoveNext
        Wend
        Set oUser = Nothing
        Close #logfile
        ret = MsgBox("All Done!", vbOKOnly, "Passwords Check")
        End
    End Sub
    
    Function GetBoiler(ByVal sFile As String) As String
        Dim fso As Object
        Dim ts As Object
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
        GetBoiler = ts.readall
        ts.Close
    End Function
    Is there some odd access rights error here, as I'm running from a completely different location to where Outlook runs!

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,900

    Re: Outlook signatures created via VB6 won't show images.

    as I'm running from a completely different location to where Outlook runs!
    is the full path to the image file relative to outlook, or is it a network path from outlook
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2015
    Location
    Cambridge, UK
    Posts
    9

    Re: Outlook signatures created via VB6 won't show images.

    Quote Originally Posted by westconn1 View Post
    is the full path to the image file relative to outlook, or is it a network path from outlook
    Hi,
    I've tried both!
    Initial attempts left the path in the .htm file as it was, i.e. local to Outlook.
    Subsequently, I tried changing the path to the full local path, e.g.
    C:\Users\<my name>\AppData\Roaming\Microsoft\Signatures\New_Teqhou_files\image001.png
    Both had the same result:

    Name:  Failed signature.jpg
Views: 1042
Size:  54.3 KB

    There should be icons for Facebook and LinkedIn showing to the right of the www.teqhou.com line, (you can see their place-markers), plus three jpegs beneath for my company logo, MS Partners, and MS Dynamics.
    If it makes any difference, I'm running Office 2013 on Windows 8.1

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,845

    Re: Outlook signatures created via VB6 won't show images.

    Maybe this discussion on StackOverflow can help you further:
    http://stackoverflow.com/questions/8...ure-in-outlook

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2015
    Location
    Cambridge, UK
    Posts
    9

    Resolved Re: Outlook signatures created via VB6 won't show images.

    Quote Originally Posted by Arnoutdv View Post
    Maybe this discussion on StackOverflow can help you further:
    http://stackoverflow.com/questions/8...ure-in-outlook
    Many thanks for that link. That sorted it for me!

    Dead simple, really! I just had to add a .Getinspector line to make Outlook create a blank message with the default signature, locate the beginning of the signature block, which follows immediately after "<div class=WordSection1>", then insert my constructed message text into the standard e-mail that had just been created:

    Code:
                strBody = strBody & "Please contact me, by e-mail or Skype, if you have any difficulties with this.<BR/>"
                strBody = strBody & "</p></pre>"    'last line of constructed message
                With oEmail
                    .BodyFormat = olFormatHTML
                    .Recipients.Add (oUser.get("mail"))
                    .Subject = "Network Password Expiration Notice"
                    .Importance = olImportanceHigh
                    .ReadReceiptRequested = False
                    .GetInspector = ret
                    .HTMLBody = Replace(oEmail.HTMLBody, "<div class=WordSection1>", "<div class=WordSection1>" & strBody)
                    .Display  'Show the email message and allow for editing before sending
               End With
               Set oEmail = Nothing
    Thanks for all your help. I'm now feeling really pleased with myself!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width