I want to code an outlook addin and try to replace a placeholder in an outlook mail with the salutation of the recipient. I get the salutation from AD. I tried this in ItemSend, but the body for different recipients contains always the last replacement.
Then i generated a new mail per recipient. That seems to be the right way, but there is the next problem. The mailitem.htmlbody contains not the same content like shown in the outlook message window. All styles of the original message are lost and for instance my signature is bad formatted.
Has anyone an idea to solve my problem?
First of all, if want to send an individual "salutation" for each recipient you need to send separate emails. For example, you can check out the list of recipients in the ItemSend event and if it contacts more than one entry in the collection you can cancel the send operation setting the Cancel parameter to true and prepare an individual email to each recipient from the collection.
You may consider using the Word object model instead of modifying the raw HTML markup of the body. The WordEditor of the Inspector class returns an instance of the Document class from the Word object model. The Chapter 17: Working with Item Bodies describes all possible ways of working with item bodies.
Related
In outlook, I want all the people sending me emails with the object as "testintro" let's say, to be replied with their OWN email. I want them to receive exactly what they sent me. Is it possible to create that rule?
Yes, it is possible. But not with a rule. Instead, you can develop a VBA macro.
You can create a VBA macro where you could handle the NewMailEx event of the Application class. The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. Use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem.
So, you may get an instance of the arrived mail item and call the Reply method to reply instantly. The method creates a reply, pre-addressed to the original sender, from the original message. You may find the following articles helpful:
How To: Create and send an Outlook message programmatically
How To: Fill TO,CC and BCC fields in Outlook programmatically
How To: Change an Outlook e-mail message before sending using C# or VB.NET
Challenge description
I'd like to extract the header information from emails in an Outlook folder.
This works so far.
But there are Emails which where scanned by Spamassassin and found as being SPAM. So the SPAM Mail is attached to a new mail as Mail-Attachment.
Now i'd like to extract the header information from the original email-header.
What I already have
I am getting the header information from the 'normal'- mail and can access the Outlook-mail-item and also found the attachement.
What I look for
The easiest way to get the attachment as Outlook-mail-item so that I can perform the getHeader-operation operation. And, if possible without the need to open the attached mail.
Is there a way from the olmailItem to the attached mail (.msg-file) without opeining the attachment?
(Manually - with opening the mail - this can be done by opening the attached mail and look at the message options.)
Outlook does not let you directly access embedded message attachments. The best you can do is call Attachment.SaveAsFile to save the embedded message attachment as an MSG file, then open it using Application.Session.OpenSharedItem.
If you using Redemption is an option (I am its author), it exposes EmbeddedMsg property on both the Attachment object (returned by the SafeMailItem object) and RDOAttachment object (returned by the RDOMail object).
I am trying to get started with VBA in outlook and I was wondering if anyone had code that copied and pasted the content of one cell from a table in an outlook mail to another mail (only the content - not the cell or table)?
A small piece of example code would be great.
Best regards
It looks like you need to parse the message body and find the required value. Then paste it to another message body.
The Outlook object model provides three main ways for working with item bodies:
Body.
HTMLBody.
The Word editor. The WordEditor property of the Inspector class returns an instance of the Word Document which represents the message body. So, you can use the Word object model do whatever you need with the message body.
See Chapter 17: Working with Item Bodies for more information.
Also you may find the Getting Started with VBA in Outlook 2010 article helpful.
Seeking your insight on this process:
I want to forward the latest email received only not including the entire thread of the emails. Can I forward that email without manually deleting the previous emails on the thread?
I want to automatically send the NEWEST/LATEST emails received to a specific email address without the previous emails on the thread.
What I'm thinking is, I will set the "BLUE LINE" as reference, for starting position and ending position. Because as we all know, whenever we forward a HTML email, there's a blue line separating emails received.
Is it possible to do that? Set blue line as reference, then delete everything not inside the lines.
You can edit the message body at runtime using VBA macros. The Outlook object model provides three main ways for working item bodies:
Body - a string representing the clear-text body of the Outlook item.
HTMLBody - a string representing the HTML body of the specified item.
Word editor - the Microsoft Word Document Object Model of the message being displayed. The WordEditor property of the Inspector class returns an instance of the Document class from the Word object model which you can use to set up the message body.
You can read more about all these ways in the Chapter 17: Working with Item Bodies. It us up to you which way is to choose to customize the message body.
If you are new to VBA macros, see Getting Started with VBA in Outlook 2010.
Working in a Windows Forms application and VB.NET.
I need to pop open an Office "New Message" window, populate the "To" address, and place an OFT template in the body of the message. I do not need to modify anything in the template.
To open the new message with the template, i could:
Diagnostics.Process.Start("MyFile.oft")
But this will not help with setting the TO address, or subject.
I also don't want to download any third party add-ons.
Any help??
You can use the Outlook Object Model and call Application.CreateItemFromTemplate. You can then set Subject/To/CC/BCC properties and the Recipients collection on the returned MailItem object.