Solved

VB6 Inserting Outlook Signature using vb6

Posted on 2010-09-01
7
1,501 Views
Last Modified: 2013-11-25
I use the following code to send an email
Public Sub SendEmail(iRecipient, iSubject As String, iAttach As String, iBody As String)
Dim myOlApp As Outlook.Application
Dim myItem As MailItem
Dim myAttachments As Attachments
Dim MyItemSize As Long
Dim sUserName As String
Dim oInsp As Outlook.Inspector

    Set myOlApp = CreateObject("Outlook.Application")
    Set myItem = myOlApp.CreateItem(olMailItem)
    Set myAttachments = myItem.Attachments
    Set oInsp = myItem.GetInspector
    myItem.Recipients.Add iRecipient
    myItem.Subject = iSubject
    myItem.Attachments.Add iAttach
    myItem.ReadReceiptRequested = True
'    myItem.Body = iBody
    myItem.Display
End Sub

This code displays the correct default signature. As soon as I uncomment the line 'myItem.Body = iBody' it deletes the signature and only shows the body text- Any Ideas

0
Comment
Question by:Martin-Swannie
  • 4
  • 3
7 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 33579024
did u check what was passed into iBody? Could that text have the signature added in?
instead of commenting out, what if you passed in a empty string, does that still produce a signature?
0
 

Author Comment

by:Martin-Swannie
ID: 33579288
I will try passing an empty string and let u know
0
 

Author Comment

by:Martin-Swannie
ID: 33579306
Passing an empty string also deletes the signature
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 65

Expert Comment

by:rockiroads
ID: 33579480
can you check the contents of ibody? maybe that string contains the signature
0
 

Author Comment

by:Martin-Swannie
ID: 33579973
ibody only contains text which the user enters in a text box. Under the text I want to display the Default Outlook Signature. If I exclude the ibody then the Signature displays correctly. As soon as ibody is added it deletes the Signature and only displays the ibody text. i.e. it does not insert iBody it seems to overwrite the Signature
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 33580574
So you have definitely inspected the text passed into iBody? (by the way, it should really read sBody as i refers to a numeric).

From what I gather, outlook automation does not include signature by default. Only way I knew how to add a signature when I used outlook auto is to open the signature file and add in the contents into iBody.
0
 

Accepted Solution

by:
Martin-Swannie earned 0 total points
ID: 33585160
I have solved the problem by not adding the line "myItem.Body = iBody" and replaced it with the following using sendkeys. It works perfectly and the default signature is displayed. The iBody string must have "," between the text which are converted to {enter}

Public Sub SendEmail(iRecipient, iSubject As String, iAttach As String, iBody As String)
Dim tStr As String
Dim myOlApp As Outlook.Application
Dim myItem As MailItem
Dim myAttachments As Attachments
Dim MyItemSize As Long
Dim sUserName As String
Dim oInsp As Outlook.Inspector

    Set myOlApp = CreateObject("Outlook.Application")
    Set myItem = myOlApp.CreateItem(olMailItem)
    Set myAttachments = myItem.Attachments
    Set oInsp = myItem.GetInspector
    If iRecipient <> "" Then
        myItem.Recipients.Add iRecipient
    End If
    myItem.Subject = iSubject
    If Right(iAttach, 1) <> "\" Then
        myItem.Attachments.Add iAttach
    End If
    myItem.ReadReceiptRequested = True
    myItem.Display
   
    Dim iTxt As String
    Dim iLeft As Integer
    tStr = iBody
    Do While True
        iLeft = InStr(1, tStr, ",", vbTextCompare)
        If iLeft > 0 Then
            iTxt = Left(tStr, iLeft - 1)
            SendKeys iTxt, True
            SendKeys "{enter}", True
            tStr = Right(tStr, Len(tStr) - iLeft)
        Else
            SendKeys tStr, True
            SendKeys "{enter}", True
            Exit Do
        End If
    Loop
End Sub
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now