pauldonson
asked on
Adding a picture OR Outlook signature to email created by VBA and redemption
I have an Access ADP project that creates an email programatically, saves it in the database and then sends it.
I have been asked by several users if we can add the company logo to the email signature. I figure that there are two ways of doing this:
1) add the picture to the HTMLBody of the email
2) forget the signature in the code and add the Outlook signature instead
I would prefer option 1) as this retains the consistancy of the signatures that the project enforces.
Much has been written on this subject but I cannot find anything that suits my circumstances, my constraints are:
It cannot reference anything other than Outlook and Redemption. The Outlook must be referenced using late binding as I have multiple version of Outlook I must support.
I have tried the obvious (to me anyway) approach of putting in HTML code to attach the image but this seems to have unpredictable results.
Has anyone done this and come up with a satisfactory solution?
Thanks.
I have been asked by several users if we can add the company logo to the email signature. I figure that there are two ways of doing this:
1) add the picture to the HTMLBody of the email
2) forget the signature in the code and add the Outlook signature instead
I would prefer option 1) as this retains the consistancy of the signatures that the project enforces.
Much has been written on this subject but I cannot find anything that suits my circumstances, my constraints are:
It cannot reference anything other than Outlook and Redemption. The Outlook must be referenced using late binding as I have multiple version of Outlook I must support.
I have tried the obvious (to me anyway) approach of putting in HTML code to attach the image but this seems to have unpredictable results.
Has anyone done this and come up with a satisfactory solution?
Thanks.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
It should ... but, as I mentioned earlier, you'll need to use CDO, which you can do via Last Binding as your are with Outlook.
However, if you have Redemption you should contact the developer of that product to determine if there is a method exposed through the Redemption object model.
However, if you have Redemption you should contact the developer of that product to determine if there is a method exposed through the Redemption object model.
ASKER
Hmm, I have tried the example you gave but it just attaches the picture to the email.
ASKER
I am using Outlook/Word 2007 - I wonder if that makes a difference.
Do you then refer to the image in the email, and are you viewing it in the proper format (i.e. HTML format, not plain text)?
I don't think the version would make a difference ... although with 2007 I have to tell Outlook to view the email in HTML format ... i.e. at the top of the message in the Reading pane, I have a blue bar that says "This message was converted to plain text", and for emails with images and such I see the image as an attachment. When I right click on that blue bar, I can select Display as HTML and I then see the image in the message body.
I don't think the version would make a difference ... although with 2007 I have to tell Outlook to view the email in HTML format ... i.e. at the top of the message in the Reading pane, I have a blue bar that says "This message was converted to plain text", and for emails with images and such I see the image as an attachment. When I right click on that blue bar, I can select Display as HTML and I then see the image in the message body.
ASKER
Yes it is definitely HTML.
I do get a picture box in the body but when you expand it you can see it says:
The linked image cannot be displayed. The file may have been moved, renamed, or deleted. Verify that the link points to the correct file and location.
I do get a picture box in the body but when you expand it you can see it says:
The linked image cannot be displayed. The file may have been moved, renamed, or deleted. Verify that the link points to the correct file and location.
Can you post your code?
ASKER
This was copied from the link you sent me, the only change I have made is for late-binding.
Dim objApp As Object 'Outlook.Application
Dim l_Msg As Object 'MailItem
Dim colAttach As Object 'Outlook.Attachments
Dim l_Attach As Object 'Outlook.Attachment
Dim oSession As Object 'MAPI.Session
' CDO objects
Dim oMsg As Object 'MAPI.Message
Dim oAttachs As Object 'MAPI.Attachments
Dim oAttach As Object 'MAPI.Attachment
Dim colFields As Object 'MAPI.Fields
Dim oField As Object 'MAPI.Field
Dim strEntryID As String
' create new Outlook MailItem
Set objApp = CreateObject("Outlook.Application")
Set l_Msg = objApp.CreateItem(olMailItem)
' add graphic as attachment to Outlook message
' change path to graphic as needed
Set colAttach = l_Msg.Attachments
Set l_Attach = colAttach.Add("c:\test.jpg")
l_Msg.Close olSave
strEntryID = l_Msg.EntryID
Set l_Msg = Nothing
' *** POSITION CRITICAL *** you must dereference the
' attachment objects before changing their properties
' via CDO
Set colAttach = Nothing
Set l_Attach = Nothing
' initialize CDO session
On Error Resume Next
Set oSession = CreateObject("MAPI.Session")
oSession.Logon "", "", False, False
' get the message created earlier
Set oMsg = oSession.GetMessage(strEntryID)
' set properties of the attached graphic that make
' it embedded and give it an ID for use in an <IMG> tag
Set oAttachs = oMsg.Attachments
Set oAttach = oAttachs.Item(1)
Set colFields = oAttach.Fields
Set oField = colFields.Add(CdoPR_ATTACH_MIME_TAG, "image/jpeg")
Set oField = colFields.Add(&H3712001E, "myident")
oMsg.Fields.Add "{0820060000000000C000000000000046}0x8514", 11, True
oMsg.Update
' get the Outlook MailItem again
Set l_Msg = objApp.GetNamespace("MAPI").GetItemFromID(strEntryID)
' add HTML content -- the <IMG> tag
l_Msg.HTMLBody = "<IMG align=baseline border=0 hspace=0 src=cid:myident>"
l_Msg.Close (olSave)
l_Msg.Display
' clean up objects
Set oField = Nothing
Set colFields = Nothing
Set oMsg = Nothing
oSession.Logoff
Set oSession = Nothing
Set objApp = Nothing
Set l_Msg = Nothing
I assume you have a valid image at C:\Test.jpg?
ASKER
Yes. (just checked to make sure though!!)
I'm not sure, then ... if the image is showing up as an attachment, i'd suspect the image is being correctly transferred.
Can you send me the email? You can email it to the address in the profile.
Can you send me the email? You can email it to the address in the profile.
ASKER
Sent, I sent the message "as is" so as not to put a spanner in the works!
I received your email, and the image is attached, and I can view it, but not as an HTML message. You're using one constant in this line:
Set oField = colFields.Add(CdoPR_ATTACH _MIME_TAG, "image/jpeg")
Does your code recognize the value of CdoPR_ATTACH_MIME_TAG correctly? According to the link below, it's &H370E001E. Do you currently have a Reference to the CDO library, which is where this comes from? Try temporarily setting a reference to the CDO library and see what happens.
http://msdn.microsoft.com/en-us/library/ms526356(EXCHG.10).aspx
Set oField = colFields.Add(CdoPR_ATTACH
Does your code recognize the value of CdoPR_ATTACH_MIME_TAG correctly? According to the link below, it's &H370E001E. Do you currently have a Reference to the CDO library, which is where this comes from? Try temporarily setting a reference to the CDO library and see what happens.
http://msdn.microsoft.com/en-us/library/ms526356(EXCHG.10).aspx
ASKER
Good point - constants often catch me out using late binding.
Unfortunately I changed the constant to the value you supplied and no change.
I tried referencing CDO (the only one I seem to have is "Microsoft CDO for Windows 2000 library" - does this sound correct?) and it made no difference.
Unfortunately I changed the constant to the value you supplied and no change.
I tried referencing CDO (the only one I seem to have is "Microsoft CDO for Windows 2000 library" - does this sound correct?) and it made no difference.
That sounds like the right one ... I'm using different versions and OS, so can't verify but a quick search seems to indicate that is correct.
I'm out of ideas on this one, sorry ... one of the big reasons I moved to a 3rd party utility for my emails!
I'm out of ideas on this one, sorry ... one of the big reasons I moved to a 3rd party utility for my emails!
ASKER
OK, thanks for your help.
ASKER
I got it working with a bit of faffing!
ASKER
To save me loads of time do you happen to know if the bits relating to inserting a picture will work with the Outlook/Redemption object model?