I am creating an outlook add in which needs to make modifications on the TO and CC fields before sending the message. I tried editing the TO property of the MailItem object but when I edit it, the mail doesn't get sent, it gets stuck in the Outbox. I also looked at the Recipients collection but it's read only so not of any use. Is there any mapping being maintained by Outlook between TO and Recipients collection which fails when I edit TO property?
What is the ideal way to make these changes and still have the mail be delivered properly?
Use yourMailItem.Recipients.Add("foo#bar.com") to add recipients.
To set them as CC set the recipient type to olCC (e.g. Recipients.Item(1).Type = olCC).
Related
Before sending the appointmentItem in outlook 2010 I have created an extended property and set some values. The property is not available for the recipient (recipients are using outlook and they are from the same domain).
However, the property is available in the owner's calendar item.
Any inputs about this issue is much appreciated.
Keep in mind that ApointmentItem object is never sent - Outlook creates a MeetingItem object and sends. The original ApointmentItem remains in the Calendar folder.
You can try to use Application.ItemSend event - Outlook will pass MeetingItem as the parameter, and you should be able to set the extra properties. Now where these properties will be copied by Outlook from MeetingItem in the Inbox to the new ApointmentItem is a different question...
I have already replied to your post on MSDN forums two days ago:
The fact is that a meeting item is not sent to a recipient. Instead, a corresponding meeting request is created and sent to the recipient. Just check the message class of the item when the item is sent. You can handle the ItemSend event of the Application class which is fired whenever an Microsoft Outlook item is sent, either by the user through an Inspector (before the inspector is closed, but after the user clicks the Send button) or when the Send method for an Outlook item.
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 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.
I tried to search across on StackOverflow and Google, but had no success.
Am creating a form application to accept some information for the body of an email, create a HTML email and send via Outlook.
Everywhere I looked and found sending via GMail. But I want to be able to send via outlook without user interruption.
Could someone help me with a code to call outlook, frame the message and send automatically. Also should be able to enter some extra recipients via their username on the domain and it should automatically resolve and pickup the email and send to them when sending via outlook.
The message contents may have fields like Name, Email Address, Phone Number, Address. This should all sit inside a HTML email in a table.
Whilst i am puzzled you cant find what you are looking for i am going to provide an answer as the title is very clear so it could simplify searching for others in the future.
Dim Outlook As New Microsoft.Office.Interop.Outlook.Application
Dim MailItem As Microsoft.Office.Interop.Outlook.MailItem
MailItem = Outlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
With MailItem
.HTMLBody = "put the body of your email here as a string"
.Subject = "Subject Line Info"
'use the below to change from the default email account
.SentOnBehalfOfName = "YourEmail#yourdomain.you"
'you can add multiple recipients using .Add()
.Recipients.Add("Recipient#theirdomain.them")
'examples of other optional arguments that can be included
.Attachments.Add([file])
.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh
.Display() 'opens the email for checking prior to sending or use .Send()
End With
As per the comment from Rahul below you will also need to add a Reference to the Microsoft Office 14.0 Object Library.
I'm having some trouble making a plugin that will send an email using the users settings without having the item go to Sent Items. I thought I could simply grab the EntryId before sending it and then dlete it from the sent items and deleted folder restricted by that entryID but the problem is that after using mailItem.Send the mail gets sent to the outbox.
I tried looping and rechecking the sent items folder but the email doesn't seem to leave the outbox while this looping is going on.
Does anyone have any suggestions for getting around this?
All you need to do is set the MailItem.DeleteAfterSubmit property to true.