Hi,
I'm working on automating outlook's forward event using C#.net. I'm creating a console program and the exe will be scheduled to run at certain frequency. When the exe runs, it will login in to specific user account and check MailItems in the inbox.
I want to forward specific mails to specific mail addresses. I tried creating a new mail with the contents, subject and attachments of the existing mailItem and then using 'send' to send to specific user. but doesn't work and gives error similar to 'mail bounced notice'
Does anybody has any idea about how to invoke 'forward' event of outlook while working in console program of c#?
Minakshi.
Loading
Minakshi MahadikPosted Jun 27, 2012, 9:45 AM
Posted Jun 21, 2012, 12:11 AM
using System;
using System.Reflection; // to use Missing.Value
// TO DO: If you use the Microsoft Outlook 11.0 Object Library, uncomment the following line.
// using Outlook = Microsoft.Office.Interop.Outlook;
namespace SendHTMLMail
{
public class Class1
{
public static int Main(string[] args)
{
try
{
// Create the Outlook application.
Outlook.Application oApp = new Outlook.Application();
// Get the NameSpace and Logon information.
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
// Log on by using a dialog box to choose the profile.
oNS.Logon(Missing.Value, Missing.Value, true, true);
// Alternate logon method that uses a specific profile.
// TODO: If you use this logon method,
// change the profile name to an appropriate value.
//oNS.Logon("YourValidProfile", Missing.Value, false, true);
// Create a new mail item.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
// Set the subject.
oMsg.Subject = "Send Using OOM in C#";
// Set HTMLBody.
\n" +String sHtml;
sHtml = "\n" +
"
"
"\n" +
"
\n" +
"
Inline graphics
\n" +"\n" +
"";
oMsg.HTMLBody = sHtml;
// Add a recipient.
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
// TODO: Change the recipient in the next line if necessary.
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("email address");
oRecip.Resolve();
// Send.
oMsg.Send();
// Log off.
oNS.Logoff();
// Clean up.
oRecip = null;
oRecips = null;
oMsg = null;
oNS = null;
oApp = null;
}
// Simple error handling.
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
// Default return value.
http://www.c-sharpcorner.com/UploadFile/casperboekhoudt/SendingEmailsThroughOutlook12052005000124AM/SendingEmailsThroughOutlook.aspxreturn 0;
}
}
}
http://support.microsoft.com/kb/310263
http://www.c-sharpcorner.com/UploadFile/rambab/OutlookIntegration10282006032802AM/OutlookIntegration.aspx
http://www.programminghelp.com/programming/dotnet/access-your-email-within-outlook-final-part-c/