How to integrate company logo with auto send using vb.net
Hi Dave,
I followed your instruction but it did not come out right. Here's my
code:
Dim oApp As Outlook._Application
oApp = New Outlook.Application
Dim oMsg As Outlook._MailItem
oMsg = CType(oApp.CreateItemFromTemplate("C:\BOSLH.oft"),
Outlook.MailItem)
oMsg.Subject = "Testing..."
oMsg.HTMLBody = "Testing..." & vbCrLf & vbCrLf & "Line 4"
oMsg.To = "
The email that came thru did not have the logo as designed. Instead,
it has a blank look to it and the logo is attached with the email. Can
you please give me more instruction on how to carry this out, "You'll
need to find the point after the IMG tag for your logo where you want
to insert the text of the message that you want to send". I noticed
that vbCrLf does not work with HTMLBody. A million thanks to you.
Dave Kane [MVP - Outlook] wrote:
Option 2 is less technically challenging, so why not start with that.
Step #1 is creating a template in the Outlook HTML editor:
1. Create a new blank message using your stationery
2. From the main Outlook menu (I'm using Outlook 2003) click Actions New
Mail Message Using Microsoft Office Outlook (HTML)
3. Put your cursor in the body of the stationery message, click Ctrl+A to
select all and then Ctrl+C to copy
4. Put your cursor in the body of the Outlook HTML message and click Ctrl+V
to paste. That won't grab the background image if you have spec'd one - to
add that you will need to use Format Background, etc. from the message
menu
5. Create an Outlook template file (OFT) from the HTML message by clicking
File Save As... and selecting Outlook template (*.oft) as the type. Save
it to a directory that your WinForms application can access
Step #2 is using the template in your code when you create a new item.
Assuming your Outlook application object is mobjOlApp and the template is at
C:\CompanyLogo.oft
Dim myMail as Outlook.MailItem
myMail =
CType(mobjOlApp.CreateItemFromTemplate("C:\Company Logo.oft"),Outlook.MailItem)
myMail.HTMLBody will have the full HTML source for your message, with
HTML, HEAD and BODY tags, etc. You'll need to find the point after the
IMG tag for your logo where you want to insert the text of the message
that you want to send, wherever that may be. Modify the value of HTMLBody so
that it includes your text. Then set the values of Subject, add your
recipient(s) and call Send. Does that get you what you need?
wrote in message
oups.com...
Hi Dave,
Firstly, thank you for your help. I googled on this topic for the past
day and a half but came up empty. I'm still green in this area so I
would appreciate it very much if you have some code sample for me to
look at -- for Option 1 and/or 2. At least now I know it can be done.
I was ready to give in and tell me boss otherwise. I really, really
appreciate your help!!! Thanks a million.
Dave Kane [MVP - Outlook] wrote:
Outlook stationery really belongs to the Word editor, and there may be an
easy way to do this through Word automation. I can suggest two different
approaches using Outlook
Option #1: You can set the HTMLBody property of your Outlook.MailItem to
repro the stationery that you created, including whatever formatted text
you
want in the email. But if you look at the HTML source for your stationery
you will see that the src property of the IMG tag for the company logo
looks
something like src="cid:760521916@20082002-17cb". That cid value
corresponds
to the PR_ATTACH_CONTENT_ID (&H3712001E) property of a hidden attachment
to
the message that holds the image. So in addition to specifying the HTML
source of the message by setting HTMLBody you would need to add the logo
image as an attachment and set its PR_ATTACH_CONTENT_ID. The Outlook
object
model will allow you to add the attachment, but to set any properties on
an
attachment you would have to use ExMAPI or a component like Redemption.
That's the most flexible approach since you can easily change the HTML
and
the image.
Option #2: Reproduce your stationery template using the Outlook HTML
editor,
save it as as an OFT file and then use Outlook's CreateItemFromTemplate
method to create your new MailItem. The HTMLBody property of the new
MailItem will contain the full HTML source for the message, including an
IMG
src pointing to the hidden attachment of your logo image. You would need
to
read that property, parse it to find where to place your message text and
then reset the value of HTMLBody. The coding is simpler, but you need to
rebuild the OFT file if your logo changes.
wrote in message
oups.com...
Hi,
In my VB.NET Windows form application, I'm using the Outlook object to
compose and
automatically send email. The spec also requires that I integrate the
company logo on the top of the email to look like the company
letterhead. I tried creating a html page with the company logo design
on it and set
it as the default stationery. It works when I compose a new email
manually from Outlook. But when the email is composed and sent from
VB.NET code using the Outlook MailItem, for reason beyond my level of
understanding, the default stationery is not used. Instead all I see
is a blank template. I'm fairly new at this game. I greatly
appreciate your help.
|