Outlook and c#

  • Thread starter Thread starter lo75
  • Start date Start date
L

lo75

Hello,

I'd like to create an .exe for use outlook and c# ,

someone can say me how to do?

I have a script that works but i don't know how to modify it and then
create the .exe

namespace OutlookEmail
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Email
{
public static msoutl9.Application objOutlook = new
msoutl9.ApplicationClass();
public static msoutl9.Folders objFolders =
objOutlook.GetNamespace("MAPI").Folders;
public static msoutl9.NameSpace objFolder =
objOutlook.GetNamespace("MAPI");
static void Main(string[] args)
{

msoutl9.Application objOutlook = new msoutl9.ApplicationClass();
msoutl9.NameSpace objFolder = objOutlook.GetNamespace("MAPI");
msoutl9.Explorer objExplorer =
objOutlook.Explorers.Add(objFolder.GetDefaultFolder(OlDefaultFolders.olFolderDrafts),
OlFolderDisplayMode.olFolderDisplayNormal);
objExplorer.Activate();

msoutl9.MailItem objMail = (msoutl9.MailItem)
objOutlook.CreateItem(OlItemType.olMailItem);
objMail.To = "user@localhost";
objMail.Subject = "sample email";
objMail.Body = "Hi,\nI'm your sample email.";
objMail.Save();
objOutlook.Quit();
}
}
}


Thanks
 
Hi, here is a small sample app.

I use OutlookXP (Outlook10)
If I try to send Email a security warning is shown.
However, with Outlook9 no warning should be popup.

You can bypass this warning by using a dll called redemption.
you can find it at www.dimastr.com

using System;
using System.Collections;

using System.Data;

//Add reference to Outlook Com-Object

//You can also download and use the .net Office PIA's

using Outlook = Microsoft.Office.Interop.Outlook ;

using System.Runtime.InteropServices;

//http://www.x4u.de Helmut Obertanner

namespace X4U.electronix

{

/// <summary>

/// Summary an App to send Email over Outlook Objectmodel

/// </summary>

public class EmailApp

{

public EmailApp()

{

}

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main()

{

//Create the Oulook Application Object

Outlook.Application olApp = new Outlook.Application();


//Create th Namespace Object

Outlook.NameSpace olNS = olApp.GetNamespace ("Mapi");


//Logon to Outlook if it's not running

//The Profilename is "Outlook", password ""

olNS.Logon("Outlook","",false,false);

//Create a new Mailitem (in the Draftsfolder)

Outlook.MailItem objMail = (Outlook.MailItem) olApp.CreateItem
(Outlook.OlItemType.olMailItem );

objMail.To = "user@localhost";

objMail.Subject = "sample email";

objMail.Body = "Hi,\nI'm your sample email.";

objMail.Save();


//Send the Email

objMail.Send ();


//Start Send/Receive

olApp.Session.SyncObjects[1].Start ();

objMail = null;

//Logoff from Session

olNS.Logoff();

olNS = null;

olApp = null;

//Release Marshal-Com Objects

System.Runtime.InteropServices.Marshal.ReleaseComObject (objMail);

System.Runtime.InteropServices.Marshal.ReleaseComObject (olNS);

System.Runtime.InteropServices.Marshal.ReleaseComObject (olApp);


}

}

}



--
regards,
Helmut Obertanner
DATALOG Software AG
http://www.datalog.de
[obertanner at datalog dot de]


lo75 said:
Hello,

I'd like to create an .exe for use outlook and c# ,

someone can say me how to do?

I have a script that works but i don't know how to modify it and then
create the .exe

namespace OutlookEmail
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Email
{
public static msoutl9.Application objOutlook = new
msoutl9.ApplicationClass();
public static msoutl9.Folders objFolders =
objOutlook.GetNamespace("MAPI").Folders;
public static msoutl9.NameSpace objFolder =
objOutlook.GetNamespace("MAPI");
static void Main(string[] args)
{

msoutl9.Application objOutlook = new msoutl9.ApplicationClass();
msoutl9.NameSpace objFolder = objOutlook.GetNamespace("MAPI");
msoutl9.Explorer objExplorer =
objOutlook.Explorers.Add(objFolder.GetDefaultFolder(OlDefaultFolders.olFolde
rDrafts),
OlFolderDisplayMode.olFolderDisplayNormal);
objExplorer.Activate();

msoutl9.MailItem objMail = (msoutl9.MailItem)
objOutlook.CreateItem(OlItemType.olMailItem);
objMail.To = "user@localhost";
objMail.Subject = "sample email";
objMail.Body = "Hi,\nI'm your sample email.";
objMail.Save();
objOutlook.Quit();
}
}
}


Thanks
 
Back
Top