本文整理汇总了C#中Application.GetNamespace方法的典型用法代码示例。如果您正苦于以下问题:C# Application.GetNamespace方法的具体用法?C# Application.GetNamespace怎么用?C# Application.GetNamespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Application
的用法示例。
在下文中一共展示了Application.GetNamespace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOutlookApplication
private void GetOutlookApplication(out bool disposeOutlookInstances,
out Application application,
out NameSpace nameSpace, string profileName)
{
// Check whether there is an Outlook process running.
if (Process.GetProcessesByName("OUTLOOK").Any())
{
// If so, use the GetActiveObject method to obtain the process and cast it to an Application object.
application =
Marshal.GetActiveObject("Outlook.Application") as Application;
disposeOutlookInstances = false;
nameSpace = null;
if (application != null)
{
nameSpace = application.GetNamespace("MAPI");
if (!string.IsNullOrEmpty(profileName) && !nameSpace.CurrentProfileName.Equals(profileName))
{
throw new InvalidOperationException(
$"Current Outlook instance is opened with a Different Profile Name ({nameSpace.CurrentProfileName}).{Environment.NewLine}Close Outlook and try again.");
}
}
}
else
{
// If not, create a new instance of Outlook and log on to the default profile.
application = new Application();
nameSpace = application.GetNamespace("MAPI");
nameSpace.Logon(profileName, "", false, true);
disposeOutlookInstances = true;
}
}
示例2: OutlookCalendar
public OutlookCalendar()
{
// Create the Outlook application.
Application oApp = new Application();
// Get the NameSpace and Logon information.
// Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("mapi");
NameSpace oNS = oApp.GetNamespace("mapi");
//Log on by using a dialog box to choose the profile.
oNS.Logon("", "", true, true);
//Alternate logon method that uses a specific profile.
// If you use this logon method,
// change the profile name to an appropriate value.
//oNS.Logon("YourValidProfile", Missing.Value, false, true);
// Get the Calendar folder.
UseOutlookCalendar = oNS.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
//Show the item to pause.
//oAppt.Display(true);
// Done. Log off.
oNS.Logoff();
}
示例3: Excute
public override void Excute()
{
string Result = "";
Application OutLookApp = new Application();
NameSpace OutlookNS = OutLookApp.GetNamespace("MAPI");
MAPIFolder theCal = OutlookNS.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
if (theCal.Items.Count == 0)
{
Result = "No Appointment";
}
else
{
foreach (AppointmentItem appointment in theCal.Items)
{
/*if (task.Status != OlTaskStatus.olTaskComplete)
{
Result += String.Format("\n{0}, Due({1})", task.Subject, task.DueDate);
}*/
Result += String.Format("\n{0}\n", appointment.Subject);
Result += "Location : " + appointment.Location + "\n";
if (appointment.AllDayEvent)
Result += String.Format("{0} (All day)\n", appointment.Start.ToShortDateString());
else if (appointment.Start.Subtract(appointment.End).Days == 0)
{
Result += String.Format("{0} ({1} - {2})\n", appointment.Start.ToShortDateString(), appointment.Start.ToShortTimeString(), appointment.End.ToShortTimeString());
}
else
Result += String.Format("{0} {1} - {2} {3}\n", appointment.Start.ToShortTimeString(), appointment.Start.ToShortDateString(), appointment.End.ToShortTimeString(), appointment.End.ToShortDateString());
Result += "\n";
}
}
CallProcess(new ExcutionResult(ResultFlag.Result, "", Result));
}
示例4: ReadPst
private static IEnumerable<MailItem> ReadPst(string pstFilePath)
{
List<MailItem> mailItems = new List<MailItem>();
Application app = new Application();
NameSpace outlookNameSpace = app.GetNamespace("MAPI");
// Add PST file (Outlook Data File) to Default Profile
outlookNameSpace.AddStore(pstFilePath);
string pstName = null;
foreach (Store s in outlookNameSpace.Stores)
{
if(s.FilePath.Equals(pstFilePath))
pstName = s.DisplayName;
}
MAPIFolder rootFolder = outlookNameSpace.Stores[pstName].GetRootFolder();
Folders subFolders = rootFolder.Folders;
foreach (Folder folder in subFolders)
{
ExtractItems(mailItems, folder);
}
// Remove PST file from Default Profile
outlookNameSpace.RemoveStore(rootFolder);
Console.WriteLine(mailItems.Count);
return mailItems;
}
示例5: Connect
public bool Connect()
{
try
{
_outlookObject =
System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application") as Application;
}
catch
{
_outlookObject = null;
}
if (_outlookObject == null)
{
try
{
_outlookObject = new Application();
var folder = (_outlookObject.GetNamespace("MAPI")).GetDefaultFolder(OlDefaultFolders.olFolderInbox);
folder.Display();
_outlookObject.Explorers.Add(folder, OlFolderDisplayMode.olFolderDisplayNormal);
}
catch
{
return false;
}
}
return true;
}
示例6: Excute
public override void Excute()
{
string Result = "";
Application OutLookApp = new Application();
NameSpace OutlookNS = OutLookApp.GetNamespace("MAPI");
MAPIFolder theTasks =OutlookNS.GetDefaultFolder(OlDefaultFolders.olFolderTasks);
if (theTasks.Items.Count == 0)
{
Result = "No Task";
}
else
{
foreach (TaskItem task in theTasks.Items)
{
if (task.Status != OlTaskStatus.olTaskComplete)
{
Result += String.Format("\n{0}, Due({1})", task.Subject, task.DueDate.ToShortDateString());
}
}
}
CallProcess(new ExcutionResult(ResultFlag.Result,"",Result));
}
示例7: Initialize
private void Initialize()
{
Log.Info("Initializing...");
OutlookApplication = new Application();
MapiNameSpace = OutlookApplication.GetNamespace("MAPI");
CalendarFolder = MapiNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
}
示例8: ThisAddIn_Startup
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
string pstFilePath = "sample.pst";
Outlook.Application app = new Application();
NameSpace outlookNs = app.GetNamespace("MAPI");
// Add PST file (Outlook Data File) to Default Profile
outlookNs.AddStore(pstFilePath);
MAPIFolder rootFolder = outlookNs.Stores["sample"].GetRootFolder();
// Traverse through all folders in the PST file
// TODO: This is not recursive
Folders subFolders = rootFolder.Folders;
foreach (Folder folder in subFolders)
{
Items items = folder.Items;
foreach (object item in items)
{
if (item is MailItem)
{
// Retrieve the Object into MailItem
MailItem mailItem = item as MailItem;
Console.WriteLine("Saving message {0} ....", mailItem.Subject);
// Save the message to disk in MSG format
// TODO: File name may contain invalid characters [\ / : * ? " < > |]
mailItem.SaveAs(@"\extracted\" + mailItem.Subject + ".msg", OlSaveAsType.olMSG);
}
}
}
// Remove PST file from Default Profile
outlookNs.RemoveStore(rootFolder);
}
示例9: EnviarHTmlEmail
/*
public static ResultadoTransaccion EnviarHTmlEmail(string toValue, string subjectValue, string bodyValue)
{
ResultadoTransaccion res = new ResultadoTransaccion();
try
{
oApp = new Application();
oNameSpace = oApp.GetNamespace("MAPI");
oOutboxFolder = oNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderSentMail);
_MailItem oMailItem = (_MailItem)oApp.CreateItem(OlItemType.olMailItem);
oMailItem.To = toValue;
oMailItem.Subject = subjectValue;
if (oMailItem.HTMLBody.IndexOf("</BODY>") > -1)
oMailItem.HTMLBody = oMailItem.HTMLBody.Replace("</BODY>", bodyValue);
oMailItem.SaveSentMessageFolder = oOutboxFolder;
oMailItem.BodyFormat = OlBodyFormat.olFormatHTML;
oMailItem.Send();
res.Estado = Enums.EstadoTransaccion.Aceptada;
}
catch (Exception ex)
{
res.Descripcion = ex.Message;
res.Estado = Enums.EstadoTransaccion.Rechazada;
Log.EscribirLog(ex.Message);
}
return res;
}
*/
/// <summary>
/// Metodo para el envio de Email desde el Modulo Calendario
/// </summary>
/// <param name="toValue">Email del receptor</param>
/// <param name="subjectValue">Asunto del Email</param>
/// <param name="bodyValue">Cuerpo del Email</param>
public static ResultadoTransaccion EnviarEmail(string toValue, string subjectValue, string bodyValue)
{
ResultadoTransaccion res = new ResultadoTransaccion();
try
{
oApp = new Application();
oNameSpace = oApp.GetNamespace("MAPI");
oOutboxFolder = oNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderSentMail);
_MailItem oMailItem = (_MailItem)oApp.CreateItem(OlItemType.olMailItem);
oMailItem.To = toValue;
oMailItem.Subject = subjectValue;
oMailItem.Body = bodyValue;
oMailItem.SaveSentMessageFolder = oOutboxFolder;
oMailItem.BodyFormat = OlBodyFormat.olFormatRichText;
oMailItem.Send();
res.Estado = Enums.EstadoTransaccion.Aceptada;
}
catch (Exception ex)
{
res.Descripcion = ex.Message;
res.Estado = Enums.EstadoTransaccion.Rechazada;
Log.EscribirLog(ex.Message);
}
return res;
}
示例10: ConversationTracking
public ConversationTracking(IMailSelector selection)
{
_outlookApplication = new Application();
_ns = _outlookApplication.GetNamespace("MAPI");
_sent = _ns.GetDefaultFolder(OlDefaultFolders.olFolderSentMail);
_selection = selection;
Logger.LogInfo("EMAILTRACKING: Initialised Conversation Tracking");
}
示例11: MailSelection
public MailSelection()
{
_outlookApplication = new Application();
_ns = _outlookApplication.GetNamespace("MAPI");
_inspector = _outlookApplication.ActiveInspector();
_explorer = _outlookApplication.ActiveExplorer();
Logger.LogInfo("EMAILTRACKING: Initialised Mail Selection");
}
示例12: OutlookWrapper
public OutlookWrapper()
{
OutlookApplication = new Application();
OutlookNameSpace = OutlookApplication.GetNamespace("MAPI");
// Automatically log in.
OutlookNameSpace.Logon(Profile: null, Password: null, NewSession: false, ShowDialog: false);
}
示例13: SimpleFinder
public SimpleFinder(IMeetingRoomRepository rep)
{
outlookApp = new Microsoft.Office.Interop.Outlook.Application();
outlookNs = outlookApp.GetNamespace("MAPI");
roomRepository = rep;
foreach (MeetingRoom mr in roomRepository.MeetingRooms)
{
recRooms.Add(outlookNs.CreateRecipient(mr.Email));
}
}
示例14: Send
public void Send(System.Net.Mail.MailMessage message)
{
if (!OutlookIsRunning)
{
LaunchOutlook();
}
Recipients oRecips = null;
Recipient oRecip = null;
MailItem oMsg = null;
try
{
_myApp = new Application();
oMsg = (MailItem)_myApp.CreateItem(OlItemType.olMailItem);
oMsg.HTMLBody = message.Body;
oMsg.Subject = message.Subject;
oRecips = (Recipients)oMsg.Recipients;
foreach (var email in message.To)
{
oRecip = (Recipient)oRecips.Add(email.Address);
}
foreach (var email in message.CC)
{
oMsg.CC += string.Concat(email, ";");
}
List<string> filenames = Attach(message.Attachments, oMsg);
oRecip.Resolve();
(oMsg as _MailItem).Send();
_mapiNameSpace = _myApp.GetNamespace("MAPI");
DeleteTempFiles(filenames);
Thread.Sleep(5000);
}
finally
{
if (oRecip != null) Marshal.ReleaseComObject(oRecip);
if (oRecips != null) Marshal.ReleaseComObject(oRecips);
if (oMsg != null) Marshal.ReleaseComObject(oMsg);
if (_mapiNameSpace != null) Marshal.ReleaseComObject(_mapiNameSpace);
if (_myApp != null) Marshal.ReleaseComObject(_myApp);
}
}
示例15: SendEmail
public void SendEmail(string sender, string recipient, string subject, string body)
{
Application app = new Application();
var mapi = app.GetNamespace("MAPI");
mapi.Logon(ShowDialog: false, NewSession: false);
var outbox = mapi.GetDefaultFolder(OlDefaultFolders.olFolderOutbox);
MailItem email = app.CreateItem(OlItemType.olMailItem);
email.To = recipient;
email.Subject = subject;
email.Body = body;
email.Send();
}