How do I use an Add In to suppress the outlook security warning?


G

Guest

Hi, I'm getting the outlook warning message: "A program is trying to access
e-mail addresses you have stored in Outlook..." Of course followed by the "A
program is trying to automatically send e-mail..." I've looked exhaustively
on MSDN and the newsgroups to find a solution that I understand how to use.
I need to have my solution packaged with my installation script. I don't
really want the "ClickYes" utility, because I'm hoping to have a solution
that installs everything it needs automatically. As far as I understand, the
best thing for me to do is to create a Add In which exposes the Outlook
properties I need to use? As it is now: here's my Outlook Accessing class:

public class CPOutlook {

private Outlook.Application outlook;
private Outlook._NameSpace nameSpace;
private Outlook._MailItem mail;
private Outlook.Recipient recip;
private Outlook._ContactItem contactItem;

public CPOutlook() {
outlook = new Outlook.ApplicationClass();
nameSpace = (Outlook.NameSpace)outlook.GetNamespace("MAPI");
}

public void CreateMailItem() {
mail = (Outlook.MailItem)outlook.CreateItem(Outlook.OlItemType.olMailItem);
}

public void AddMessage(string messageString)
{
mail.Body = messageString.ToString();
}

public string getSender()
{
return mail.SenderEmailAddress.ToString();
}

public string getCurrentUser()
{
return nameSpace.CurrentUser.Name.ToString();
}

public void AddSubject(string subject)
{
mail.Subject = subject.ToString();
}

public void AddAttachments(string[] attachmentArray)
{
for (int i=0; i<attachmentArray.Length; i++)
{
string sSource = attachmentArray;
if (sSource != "")
{
string sDisplayName = attachmentArray;
int iPosition = (int)mail.Body.Length + 1;
int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
Outlook.Attachment oAttach =
mail.Attachments.Add(sSource,iAttachType,iPosition,sDisplayName);
}
}
}

public void SendMessage()
{
mail.Save();
mail.Send();
}

public void SendVCard(int contactID) {
DataSet ds = new
Contact(GlobalConfiguration.GetInstance().ConnectionString).GetContact(contactID);
contactItem =
(Outlook.ContactItem)outlook.CreateItem(Outlook.OlItemType.olContactItem);
contactItem.Email1Address = ds.Tables[0].Rows[0]["EmailName"].ToString();
contactItem.LastName = ds.Tables[0].Rows[0]["LastName"].ToString();
contactItem.FirstName = ds.Tables[0].Rows[0]["FirstName"].ToString();
contactItem.JobTitle = ds.Tables[0].Rows[0]["Title"].ToString();
contactItem.CompanyName = ds.Tables[0].Rows[0]["CompanyName"].ToString();
contactItem.MailingAddressStreet =
ds.Tables[0].Rows[0]["Address"].ToString() + '\r' +
ds.Tables[0].Rows[0]["Suite"].ToString();
contactItem.MailingAddressCity = ds.Tables[0].Rows[0]["City"].ToString();
contactItem.MailingAddressState =
ds.Tables[0].Rows[0]["StateOrProvince"].ToString();
contactItem.MailingAddressPostalCode =
ds.Tables[0].Rows[0]["PostalCode"].ToString();
contactItem.BusinessTelephoneNumber =
CPUtilities.FormatPhone(ds.Tables[0].Rows[0]["WorkPhone"].ToString());
contactItem.HomeTelephoneNumber =
CPUtilities.FormatPhone(ds.Tables[0].Rows[0]["Home Phone"].ToString());
contactItem.BusinessFaxNumber =
CPUtilities.FormatPhone(ds.Tables[0].Rows[0]["FaxNumber"].ToString());
contactItem.MobileTelephoneNumber =
CPUtilities.FormatPhone(ds.Tables[0].Rows[0]["MobilePhone"].ToString());
if(contactItem != null) {
mail = contactItem.ForwardAsVcard();
}
else {
mail =
(Outlook.MailItem)outlook.CreateItem(Outlook.OlItemType.olMailItem);
}
}

public void AddRecipients(string[] recipients) {
for(int i = 0;i < recipients.Length;i++) {
if(recipients.Length > 0) {
recip = mail.Recipients.Add(recipients);
recip.Type = (int)Outlook.OlMailRecipientType.olBCC;
recip.Resolve();
}
}
}

public void AddRecipients(string[] recipients, bool useTo) {
for(int i = 0;i < recipients.Length;i++) {
if(recipients.Length > 0) {
recip = mail.Recipients.Add(recipients);
recip.Type = (int)Outlook.OlMailRecipientType.olTo;
recip.Resolve();
}
}
}
public void ShowOutlook() {
mail.Display(false);
}
}

Then I have a windows pop up that sends email: the code for that is here:

public class EmailPopup : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox EmailTextBox;
private System.Windows.Forms.Label EmailMessageLabel;
private System.Windows.Forms.TextBox RecipientTextBox;
private System.Windows.Forms.Label RecipientLabel;
private System.Windows.Forms.Button button1;
private int ContactID;
private string connectionString;
private string userName;
//private string[] attachmentArray = new string[100];
//private int attachmentCount = 0;
private System.Windows.Forms.Button AttachmentButton;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.TextBox attachmentsTextBox;
private System.Windows.Forms.Button CloseButton;
private System.Windows.Forms.Label subjectLabel;
private System.Windows.Forms.TextBox subjectTextBox;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public EmailPopup()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

public void setRecipients(string recipients)
{
this.RecipientTextBox.Text = recipients.ToString();
}

public void setContactID(int newContactID)
{
this.ContactID = newContactID;
}

public void setUserName(string user)
{
this.userName = user;
}

public void setConnectionString(string newConnectionString)
{
this.connectionString = newConnectionString;
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.EmailTextBox = new System.Windows.Forms.TextBox();
this.EmailMessageLabel = new System.Windows.Forms.Label();
this.RecipientTextBox = new System.Windows.Forms.TextBox();
this.RecipientLabel = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.AttachmentButton = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.CloseButton = new System.Windows.Forms.Button();
this.attachmentsTextBox = new System.Windows.Forms.TextBox();
this.subjectLabel = new System.Windows.Forms.Label();
this.subjectTextBox = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// EmailTextBox
//
this.EmailTextBox.AcceptsReturn = true;
this.EmailTextBox.AcceptsTab = true;
this.EmailTextBox.AllowDrop = true;
this.EmailTextBox.Location = new System.Drawing.Point(16, 144);
this.EmailTextBox.Multiline = true;
this.EmailTextBox.Name = "EmailTextBox";
this.EmailTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.EmailTextBox.Size = new System.Drawing.Size(568, 216);
this.EmailTextBox.TabIndex = 0;
this.EmailTextBox.Text = "";
//
// EmailMessageLabel
//
this.EmailMessageLabel.Location = new System.Drawing.Point(16, 128);
this.EmailMessageLabel.Name = "EmailMessageLabel";
this.EmailMessageLabel.Size = new System.Drawing.Size(100, 16);
this.EmailMessageLabel.TabIndex = 1;
this.EmailMessageLabel.Text = "Message:";
//
// RecipientTextBox
//
this.RecipientTextBox.Location = new System.Drawing.Point(16, 32);
this.RecipientTextBox.Multiline = true;
this.RecipientTextBox.Name = "RecipientTextBox";
this.RecipientTextBox.ScrollBars =
System.Windows.Forms.ScrollBars.Vertical;
this.RecipientTextBox.Size = new System.Drawing.Size(568, 40);
this.RecipientTextBox.TabIndex = 2;
this.RecipientTextBox.Text = "";
//
// RecipientLabel
//
this.RecipientLabel.Location = new System.Drawing.Point(16, 16);
this.RecipientLabel.Name = "RecipientLabel";
this.RecipientLabel.Size = new System.Drawing.Size(100, 16);
this.RecipientLabel.TabIndex = 3;
this.RecipientLabel.Text = "Recipient list:";
//
// button1
//
this.button1.Location = new System.Drawing.Point(416, 432);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(168, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Send Message";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// AttachmentButton
//
this.AttachmentButton.Location = new System.Drawing.Point(16, 376);
this.AttachmentButton.Name = "AttachmentButton";
this.AttachmentButton.Size = new System.Drawing.Size(104, 23);
this.AttachmentButton.TabIndex = 4;
this.AttachmentButton.Text = "Attachments...";
this.AttachmentButton.Click += new
System.EventHandler(this.AttachmentButton_Click);
//
// CloseButton
//
this.CloseButton.Location = new System.Drawing.Point(288, 432);
this.CloseButton.Name = "CloseButton";
this.CloseButton.Size = new System.Drawing.Size(112, 23);
this.CloseButton.TabIndex = 5;
this.CloseButton.Text = "Cancel";
this.CloseButton.Click += new System.EventHandler(this.CancelButton_Click);
//
// attachmentsTextBox
//
this.attachmentsTextBox.Location = new System.Drawing.Point(136, 376);
this.attachmentsTextBox.Multiline = true;
this.attachmentsTextBox.Name = "attachmentsTextBox";
this.attachmentsTextBox.ScrollBars =
System.Windows.Forms.ScrollBars.Vertical;
this.attachmentsTextBox.Size = new System.Drawing.Size(448, 40);
this.attachmentsTextBox.TabIndex = 6;
this.attachmentsTextBox.Text = "";
//
// subjectLabel
//
this.subjectLabel.Location = new System.Drawing.Point(16, 80);
this.subjectLabel.Name = "subjectLabel";
this.subjectLabel.Size = new System.Drawing.Size(100, 16);
this.subjectLabel.TabIndex = 7;
this.subjectLabel.Text = "Subject";
//
// subjectTextBox
//
this.subjectTextBox.Location = new System.Drawing.Point(16, 96);
this.subjectTextBox.Name = "subjectTextBox";
this.subjectTextBox.Size = new System.Drawing.Size(568, 20);
this.subjectTextBox.TabIndex = 8;
this.subjectTextBox.Text = "";
//
// EmailPopup
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(602, 466);
this.ControlBox = false;
this.Controls.Add(this.subjectTextBox);
this.Controls.Add(this.subjectLabel);
this.Controls.Add(this.attachmentsTextBox);
this.Controls.Add(this.CloseButton);
this.Controls.Add(this.AttachmentButton);
this.Controls.Add(this.button1);
this.Controls.Add(this.RecipientLabel);
this.Controls.Add(this.RecipientTextBox);
this.Controls.Add(this.EmailTextBox);
this.Controls.Add(this.EmailMessageLabel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Name = "EmailPopup";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.ResumeLayout(false);

}
#endregion

private void button1_Click(object sender, System.EventArgs e)
{
try
{
if(this.RecipientTextBox.Text.Trim() != String.Empty)
{
string delimStr = ",;";
char [] delimiter = delimStr.ToCharArray();

string callLog = "";

string[] attachmentArray =
this.attachmentsTextBox.Text.ToString().Split(delimiter,100);
CPOutlook cpo = new CPOutlook();
cpo.CreateMailItem();
callLog += "From: " + System.Environment.UserName.ToString() + "\r\n";
string[] recipients = new string[1] {this.RecipientTextBox.Text};
cpo.AddRecipients(recipients,true);
callLog += "To: ";
for (int i=0;i<recipients.Length;i++)
{
if (i > 0)
callLog += ", ";
callLog += recipients.ToString();
}
callLog += "\r\n";
string emailMessage = this.EmailTextBox.Text.ToString();
if (emailMessage == "")
emailMessage = "Message Body Empty.";
cpo.AddMessage(emailMessage);
cpo.AddSubject(this.subjectTextBox.Text.ToString());
callLog += "Subject: ";
callLog += this.subjectTextBox.Text.ToString();
callLog += "\r\n";
callLog += "Attachments: ";
callLog += this.attachmentsTextBox.Text.ToString();
callLog += "\r\n";
callLog += "Message: ";
string removeBreaksMessage = emailMessage.Replace("\r"," ");
string removeLinesMessage = emailMessage.Replace("\n"," ");
callLog += removeLinesMessage;
cpo.AddAttachments(attachmentArray);
cpo.SendMessage();
Calls.Insert(this.connectionString,this.ContactID,callLog);
//cpo.ShowOutlook();
this.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void AttachmentButton_Click(object sender, System.EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();

openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;

if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
//here goes the code to add an attachment and show it with a
//link to remove it
string filePath = openFileDialog1.FileName.ToString();
this.attachmentsTextBox.Text += filePath;
this.attachmentsTextBox.Text += ";";
//this.attachmentArray[this.attachmentCount] = filePath;
//this.attachmentCount++;
}
}

private void CancelButton_Click(object sender, System.EventArgs e)
{
this.Close();
}


}

This code works fine except for the incessant outlook warning. So, I tried
adding an Outlook Addin to my solution, then I added the code from my outlook
referencing class to that file, and changed my references around, but I was
getting a build error. I'm pretty lost as far as this goes. Thanks for the
help.

Nathan
 
Ad

Advertisements

S

Sue Mosher [MVP-Outlook]

If you're building a COM add-in, then the Application object from which you
derive all other Outlook objects needs to be the Application passed by the
OnConnection event. That is the only Application object that can be
"trusted." Note that COM add-ins are trusted only in Outlook 2003, not in
earlier versions. See http://www.outlookcode.com/d/sec.htm for other
approaches (Redemption highly recommended).
 
G

Guest

Thanks for the help! This is the first time I've made an add-in or even
dealt with outlook prgromatically, so please forgive me ignorance.

1. So, adding a outlook add-in to my Solution is a viable option for
stopping warning in 2003? The application is a windows forms based app.

2. You say the only trusted outlook is the application passed in the
OnConnecion event. So, how do I go about using this as the application my
methods are derived from? Should I in my CPOutlook constructor say:
outlook = AddIn.applicationObject();

which would hopefully set my application in my existing outlook class to be
the trusted one. Or, should I add my methods from my CPOutlook to my addin
classes trusted outlook, then in my email pop up form instead of
instantiating a CPOutlook, instantiate a AddInOutlook?

Thanks for your help, I'm just not sure how this AddIn stuff works. And I
had also looked thorough the site you pointed to before posting. I think I'm
just not making the leap to how AddIns are referenced.

And one last question. Since my add in is part of my big solution, will it
be installed by the Setup I already have, or do I have to run both setups
seperately.

Thanks so much.... :)

Nathan
 
S

Sue Mosher [MVP-Outlook]

Yes, depending on the details of your application, you might build the
application entirely as a COM add-in (which would mean that it starts when
Outlook starts) or you might include in the Outlook COM add-in only the
Outlook-related procedures necessary to support public methods that you can
call from your WIndows forms application.

The add-in itself uses the IDTExtensibility2 interface. See
http://www.outlookcode.com/d/comaddins.htm for samples you can work from
that will show you the details.

You should be able to build a setup that installs everything.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



nathan said:
Thanks for the help! This is the first time I've made an add-in or even
dealt with outlook prgromatically, so please forgive me ignorance.

1. So, adding a outlook add-in to my Solution is a viable option for
stopping warning in 2003? The application is a windows forms based app.

Yes, you can either build the application
 
G

Guest

Thanks again for all your help! I wish I could send you a thank you card or
something. Does your book explain any c# examples. I have "Building
Applications with Microsoft Outlook" but it's all VB, and I'm not really that
familiar with VB.

So... I decided that, to get a better understanding of COM Add-Ins, I
should just try building a Outlook add in seperate from my solution, just to
see if I can get it. In case It matters, I'm Running Windows Server 2003,
and Office 2003 Basic. I also have installed the Outlook PIAs.

So... I built my Outlook Add-in directly from this website.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/ol03csharp.asp

I keep coming back to this article thinking I'm missing something. Anyway,
it compiles fine, but it doesn't seem to add the add-in to outlook when I
test it. It's supposed to create a little statistics button in my outlook
standard tool bar, but it doesn't seem to be working.

I'm including the entire code from the connect.cs from the TestAddIn project
in case that helps. I feel like if I can understand this, I'll at least be
closer to my final goal.

I was hired on this project to fix a number of bugs, one of which is the
outlook security warning. So, I'm not really in a position to make the whole
thing into a AddIn. I also told the client that, since I'm building an Add
In anyway, it's probably possible to make it so every time Outlook sends a
message, the add-in queries their client database for the email, and if it
exists, it adds a entry to the contact log. Does that sound do-able? Thanks
again.

Nathan

namespace TestAddin
{
using System;
using Microsoft.Office.Core;
using Extensibility;
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Outlook;
using System.Windows.Forms;


#region Read me for Add-in installation and setup information.
// When run, the Add-in wizard prepared the registry for the Add-in.
// At a later time, if the Add-in becomes unavailable for reasons such as:
// 1) You moved this project to a computer other than which is was
originally created on.
// 2) You chose 'Yes' when presented with a message asking if you wish to
remove the Add-in.
// 3) Registry corruption.
// you will need to re-register the Add-in by building the MyAddin21Setup
project
// by right clicking the project in the Solution Explorer, then choosing
install.
#endregion

/// <summary>
/// The object for implementing an Add-in.
/// </summary>
/// <seealso class='IDTExtensibility2' />
[GuidAttribute("32C07B88-DBE3-4450-BF27-6D862664A9B2"),
ProgId("TestAddin.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
private Microsoft.Office.Core.CommandBarButton btnGetEMailStats;
/// <summary>
/// Implements the constructor for the Add-in object.
/// Place your initialization code within this method.
/// </summary>
public Connect()
{
}

/// <summary>
/// Implements the OnConnection method of the IDTExtensibility2
interface.
/// Receives notification that the Add-in is being loaded.
/// </summary>
/// <param term='application'>
/// Root object of the host application.
/// </param>
/// <param term='connectMode'>
/// Describes how the Add-in is being loaded.
/// </param>
/// <param term='addInInst'>
/// Object representing this Add-in.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnConnection(object application, Extensibility.ext_ConnectMode
connectMode, object addInInst, ref System.Array custom)
{
applicationObject =
(Microsoft.Office.Interop.Outlook.Application)application;
addInInstance = addInInst;
// If we are not loaded upon startup, forward to OnStartupComplete()
// and pass the incoming System.Array.
if(connectMode != ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}

}

/// <summary>
/// Implements the OnDisconnection method of the IDTExtensibility2
interface.
/// Receives notification that the Add-in is being unloaded.
/// </summary>
/// <param term='disconnectMode'>
/// Describes how the Add-in is being unloaded.
/// </param>
/// <param term='custom'>
/// Array of parameters that are host application specific.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnDisconnection(Extensibility.ext_DisconnectMode
disconnectMode, ref System.Array custom)
{
if(disconnectMode !=
ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref custom);
}
applicationObject = null;

}

/// <summary>
/// Implements the OnAddInsUpdate method of the IDTExtensibility2
interface.
/// Receives notification that the collection of Add-ins has changed.
/// </summary>
/// <param term='custom'>
/// Array of parameters that are host application specific.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnAddInsUpdate(ref System.Array custom)
{
}

/// <summary>
/// Implements the OnStartupComplete method of the IDTExtensibility2
interface.
/// Receives notification that the host application has completed
loading.
/// </summary>
/// <param term='custom'>
/// Array of parameters that are host application specific.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnStartupComplete(ref System.Array custom)
{
// First, get access to the CommandBars on
// the active explorer.
CommandBars commandBars =
applicationObject.ActiveExplorer().CommandBars;
try
{
// If our button is already
// on the Standard CommandBar, use it.
btnGetEMailStats = (CommandBarButton)
commandBars["Standard"].Controls["Statistics"];
}
catch
{
// OOPS! Our button is not there, so
// we need to make a new instance.
// Note that the Add() method was
// defined to take optional parameters,
// which are not supported in C#.
// Thus we must specify Missing.Value.
btnGetEMailStats = (CommandBarButton)
commandBars["Standard"].Controls.Add(1,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value);
btnGetEMailStats.Caption = "Statistics";
btnGetEMailStats.Style = MsoButtonStyle.msoButtonCaption;
}
// Setting the Tag property is not required, but can be used
// to quickly reterive your button.
btnGetEMailStats.Tag = "Statistics";
// Setting OnAction is also optional, however if you specify
// the ProgID of the Add-in, the host will automatically
// load the Add-in if the user clicks on the CommandBarButton when
// the Add-in is not loaded. After this point, the Click
// event handler is called.
btnGetEMailStats.OnAction = "!<EMailStatsAddIn.Connect>";
btnGetEMailStats.Visible = true;
// Rig-up the Click event for the new CommandBarButton type.
btnGetEMailStats.Click += new
_CommandBarButtonEvents_ClickEventHandler(
btnGetEMailStats_Click);
}

/// <summary>
/// Implements the OnBeginShutdown method of the IDTExtensibility2
interface.
/// Receives notification that the host application is being unloaded.
/// </summary>
/// <param term='custom'>
/// Array of parameters that are host application specific.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnBeginShutdown(ref System.Array custom)
{
// Get set of command bars on active explorer.
CommandBars commandBars =
applicationObject.ActiveExplorer().CommandBars;
try
{
// Find our button and kill it.
commandBars["Standard"].Controls["GetEMailStats"].Delete(
System.Reflection.Missing.Value);
}
catch(System.Exception ex)
{MessageBox.Show(ex.Message);}
}

private void btnGetEMailStats_Click(CommandBarButton Ctrl,
ref bool CancelDefault)
{
// ToDo: Implement custom logic.
string statInfo;
DateTime today = DateTime.Today;
// The stats we are tracing.
int eMailsToday = 0;
int eMailsThisMonth = 0;
int eMailSentToday = 0;
int eMailSentThisMonth = 0;
// Get items in user's inbox.
NameSpace outlookNS = applicationObject.GetNamespace("MAPI");
MAPIFolder inboxFolder
= outlookNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
// Compare time received to current day / month
// and update our counters.
foreach(object item in inboxFolder.Items)
{
MailItem mi = item as MailItem;
if(mi != null)
{
if(mi.ReceivedTime.Day == today.Day)
eMailsToday++;
if(mi.ReceivedTime.Month == today.Month)
eMailsThisMonth++;
}
}
// Build first part of statInfo string.
statInfo = string.Format("E-mails received today: {0}\n",
eMailsToday);
statInfo += string.Format("E-mails received this Month: {0}\n",
eMailsThisMonth);
statInfo += "--------------------------------------\n";
// Get items in user's sent item folder and
// test again.
MAPIFolder SentFolder =
outlookNS.GetDefaultFolder(OlDefaultFolders.olFolderSentMail);
foreach(object item in SentFolder.Items)
{
// See if current item is a MailItem
MailItem mi = item as MailItem;
if(mi != null)
{
// It is, so get day/month stats.
if(mi.SentOn.Day == today.Day)
eMailSentToday++;
if(mi.SentOn.Month == today.Month)
eMailSentThisMonth++;
}
}
// Build last part of statInfo string.
statInfo += string.Format("E-mails sent today: {0}\n",
eMailSentToday);
statInfo += string.Format("E-mails sent this Month: {0}\n",
eMailSentThisMonth);
// Show results.
MessageBox.Show(statInfo, "Current E-mail stats");

}

private Microsoft.Office.Interop.Outlook.Application applicationObject;
private object addInInstance;
}
}
 
Ad

Advertisements

S

Sue Mosher [MVP-Outlook]

No, I don't speak C# and my book predates .NET entirely. Your idea of
building a test add-in is a good one, but I don't know what the problem
might be. You might want to contact the author at the web site mentioned in
the article.
I also told the client that, since I'm building an Add
In anyway, it's probably possible to make it so every time Outlook sends a
message, the add-in queries their client database for the email, and if it
exists, it adds a entry to the contact log.

Yes, that's definitely possible, either using the Application.ItemSend event
or the MAPIFolder.Items.ItemAdd event on the Sent Items folder. (It's still
possible for a user to send a message in such a way as to bypass one or both
of those events, but those are relatively rare cases.)
--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers



nathan said:
Thanks again for all your help! I wish I could send you a thank you card
or
something. Does your book explain any c# examples. I have "Building
Applications with Microsoft Outlook" but it's all VB, and I'm not really
that
familiar with VB.

So... I decided that, to get a better understanding of COM Add-Ins, I
should just try building a Outlook add in seperate from my solution, just
to
see if I can get it. In case It matters, I'm Running Windows Server 2003,
and Office 2003 Basic. I also have installed the Outlook PIAs.

So... I built my Outlook Add-in directly from this website.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/ol03csharp.asp

I keep coming back to this article thinking I'm missing something.
Anyway,
it compiles fine, but it doesn't seem to add the add-in to outlook when I
test it. It's supposed to create a little statistics button in my outlook
standard tool bar, but it doesn't seem to be working.

I'm including the entire code from the connect.cs from the TestAddIn
project
in case that helps. I feel like if I can understand this, I'll at least
be
closer to my final goal.

I was hired on this project to fix a number of bugs, one of which is the
outlook security warning. So, I'm not really in a position to make the
whole
thing into a AddIn. I also told the client that, since I'm building an
Add
In anyway, it's probably possible to make it so every time Outlook sends a
message, the add-in queries their client database for the email, and if it
exists, it adds a entry to the contact log. Does that sound do-able?
Thanks
again.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top