I have a VSTO Outlook 2013 addin that reads properties from CurrentItem when the read mail window is open. When I get the property Sender I always get system.__comobject Why does it keep returning this?
The Sender property returns an AddressEntry object that corresponds to the user of the account from which the MailItem is sent.
//if it is a regular mail or a Meeting mail
var senderName = mail.Sendername;
//if it is a task mail
var senderName = mail.Owner;
Wish can help you!
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oApp1 = oApp.GetNamespace("MAPI");
oApp1.CurrentUser.Name;
Related
I am using Redemption and the RDO Objects. I want to be able to set the sender address so that outlook will show who the email is coming from. So I connect to Outlook and the inbox and create my msg object
app = new Application();
session = app.CreateObject("Redemption.RDOSession");
try
{
session.Logon(Program.outlookProfileName);
RDOFolder inbox = session.GetDefaultFolder(rdoDefaultFolders.olFolderInbox);
msg = inbox.Items.Add();
}
I display an email form with the from address(prepopulated based on user), the TO, subject, and body
The user fills in the to box with the intended recipient(s), the subject and the body. They click the Send button. I do the following code
msg.Recipients.ResolveAll();
msg.SentOnBehalfOfEmailAddress = SenderTB.Text;
msg.Subject = SubjectTB.Text;
msg.Body = BodyTB.Text;
msg.Send();
But the sender address does not show properly in outlook. I want the sender address to show whatever was in the SenderTB.Text. How do I set the Sender for the msg object?
Is this for a delegate Exchange mailbox? Either set the SentOnBehalfOfName (not SentOnBehalfOfEmailAddress) or SentOnBehalfOf (RDOAddressEntry).
I'm trying to programmatically click on a link which creates an email with predefined subject,to,cc,bcc and body content of the email.My requirement is, If I select an Outlook mail item and click on “Approve via mail” in my Addin, the code will search for hyperlink “Click here to Approve” in the mail body and Automatically click on the hyperlink.
The hyperlink “Click here to Approve” creates an email with predefined subject,to,cc,bcc and body content of the email.
I'm not sure how to do it with VSTO as all the other solutions suggest using JQuery and Javascript
Object selObject = this.Application.ActiveExplorer().Selection[1];
Outlook._MailItem eMail = (Outlook._MailItem)
this.Application.CreateItem(Outlook.OlItemType.olMailItem);
eMail = ((Outlook._MailItem)selObject);
if(eMail.HTMLBody.Contains("Approve"))
{
}
I'm not sure what I can write in the IF segment of the code.Please Suggest.
Outlook doesn't provide anything for opening hyperlinks. You can use the the following code (Process.Start) for opening them in the default web browser:
Process.Start("your_hyperlink");
Or just create a Mail item progrmmatically in Outlook based on the info where the Approve button was clicked.
Outlook.MailItem mail = null;
Outlook.Recipients mailRecipients = null;
Outlook.Recipient mailRecipient = null;
try
{
mail = OutlookApp.CreateItem(Outlook.OlItemType.olMailItem)
as Outlook.MailItem;
mail.Subject = "A programatically generated e-mail";
mailRecipients = mail.Recipients;
mailRecipient = mailRecipients.Add("Eugene Astafiev");
mailRecipient.Resolve();
if (mailRecipient.Resolved)
{
mail.Send();
}
else
{
System.Windows.Forms.MessageBox.Show(
"There is no such record in your address book.");
}
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message,
"An exception is occured in the code of add-in.");
}
finally
{
if (mailRecipient != null) Marshal.ReleaseComObject(mailRecipient);
if (mailRecipients != null) Marshal.ReleaseComObject(mailRecipients);
if (mail != null) Marshal.ReleaseComObject(mail);
}
Take a look at the following articles for more information and samples:
How to create and show a new Outlook mail item programmatically: C#, VB.NET
How To: Create and send an Outlook message programmatically
How To: Fill TO,CC and BCC fields in Outlook programmatically
How To: Create a new Outlook message based on a template
Im doing an automatic process on a mailbox using EWS webservices and assigning ExtendedPropertyDefinition to the messages like this:
Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition extendedPropertyDefinition =
new Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(DefaultExtendedPropertySet.Common, "Archivado", MapiPropertyType.String);
msgComplete.SetExtendedProperty(extendedPropertyDefinition, iddoc);
msgComplete.Update(ConflictResolutionMode.AlwaysOverwrite);
On the other side, I am developing an Outlook Addin who needs to evaluate on every message click, if that message has this ExtendedPropertyDefinition name defined but I dont know how can I recover the Extended property from outlook addin using Outlook class.
I dont mind If I have to use another kind of properties to be accessible from both frameworks.
I have tried using the following properties in Outlook with no luck;
item.Userproperties;
item.PropertyAccesor.GetProperty("Archivado");
item.ItemProperties;
Ok, finally I got it. I had to create the ExtendedPropertyDefinition using a Guid
and recover it from outlook using the schema on the property like this:
//Setting the property with Exchange webservice:
string guid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
Guid MY_PROPERTY_SET_GUID = new Guid(guid);
Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition extendedPropertyDefinition =
new Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(MY_PROPERTY_SET_GUID, "Archivado", MapiPropertyType.String);
//Recover the property using Outlook:
Outlook.MailItem item = (Outlook.MailItem)e.OutlookItem;
Outlook.UserProperties mailUserProperties = item.UserProperties;
dynamic property=item.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/string/{Outlook.MailItem item = (Outlook.MailItem)e.OutlookItem;
Outlook.UserProperties mailUserProperties = item.UserProperties;
dynamic property=item.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/string/{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}/Archivado");
Should be a simple question. Using C#, all I want to do is just email to the email address associated to the default profile, how do I do this? I have the following code setup:
Outlook.Application oApp = new Outlook.Application();
Outlook._NameSpace oNameSpace = oApp.GetNamespace("MAPI");
Outlook.MAPIFolder oOutboxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
oNameSpace.Logon(null, null, false, false);
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMailItem.To = oMailItem.SenderEmailAddress; //this is where it does not work.
oMailItem.Subject = "subject";
oMailItem.Body = "body";
oMailItem.SaveSentMessageFolder = oOutboxFolder;
I thought by using oMailItem.SenderEmailAddress, this would work. But it doesn't. Can anyone shed some light on this? All I want to do is send it to myself.
try oNameSpace.CurrentUser.Address; it will work to get sender email address
You'll find answers here: http://social.msdn.microsoft.com/forums/en-US/vsto/thread/3f5ec8bc-ec3d-4dda-96d4-d5dabecf0395/
My company is using Exchange 2003.
Is it possible to query exchange from .NET code to find out if someone's 'Out of Office' assisstant is on or off?
Using the Outlook Redemption library, you can get Out of Office status like this:
public bool IsOutOfOffice()
{
var outlook = new Microsoft.Office.Interop.Outlook.Application();
var rdoSession = new Redemption.RDOSession();
rdoSession.MAPIOBJECT = outlook.Session.MAPIOBJECT;
Redemption.RDOOutOfOfficeAssistant OOFA =
(_rdoSession.Stores.DefaultStore as Redemption.RDOExchangeMailboxStore).OutOfOfficeAssistant
return OOFA.OutOfOffice;
}
To check another user's status, you need to get the MAPIOBJECT for their mailbox.