static void Main(string[] args) { Outlook.Application outlookApp = new Outlook.Application(); Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem); mailItem.Subject = "My Subject"; mailItem.To = ""; mailItem.Attachments.Add(@"C:\test.pdf"); mailItem.Body = "This is my Body-Text"; mailItem.Importance = Outlook.OlImportance.olImportanceNormal; ((Outlook.ItemEvents_10_Event)mailItem).Close += MailItem_onClose; ((Outlook.ItemEvents_10_Event)mailItem).Send += MailItem_onSend; //mailItem.Display(true); // This call will make mailItem MODAL - // This way, you are not allowed to create another new mail, ob browse Outlook-Folders while mailItem is visible // Using ApplicationContext will wait until your email is sent or closed without blocking other Outlook actions. using (_context = new System.Windows.Forms.ApplicationContext()) { mailItem.Display(); System.Windows.Forms.Application.Run(_context); } if (mailWasSent) { System.Windows.Forms.MessageBox.Show("Email was sent"); } else { System.Windows.Forms.MessageBox.Show("Email was NOT sent"); } }
static public _com_OutlookExporer IsOutlookExplorerLoaded( ) { Outlook.Application outlook = null; Outlook.NameSpace nameSpace = null; _com_OutlookExporer explorer = null; _isFileNotFoundHappened = false; try { _tracer.Trace("Looking for explorer"); OutlookGUIInit.DebugMessageBox("Looking for explorer"); outlook = new Outlook.ApplicationClass(); _tracer.Trace("Outlook.Application object has been initialized properly."); nameSpace = outlook.GetNamespace("MAPI"); _tracer.Trace("Outlook.NameSpace object has been initialized properly? - " + (nameSpace != null).ToString()); explorer = new _com_OutlookExporer(outlook.ActiveExplorer()); _tracer.Trace("_com_OutlookExporer wrapper object has been initialized properly."); OutlookGUIInit.DebugMessageBox("Get ActiveExplorer"); if (explorer == null) { _tracer.Trace("Outlook explorer is not found"); } else { _tracer.Trace("Outlook explorer is found"); } } catch (FileNotFoundException exception) { _isFileNotFoundHappened = true; _tracer.TraceException(exception); } catch (COMException exception) { _tracer.TraceException(exception); } catch (InvalidComObjectException exception) { _tracer.TraceException(exception); } catch (InvalidCastException exception) { _tracer.TraceException(exception); } finally { COM_Object.Release(outlook); COM_Object.Release(nameSpace); } return(explorer); }
// // GET: /email/ public static void CreateMessageWithAttachment(string invoiceNumber) { try { Outlook.Application oApp = new Outlook.Application(); Outlook.MailItem email = (Outlook.MailItem)(oApp.CreateItem(Outlook.OlItemType.olMailItem)); Models.DYNAMICS_EXTEntities _db = new Models.DYNAMICS_EXTEntities(); string recipient = null; string messageBody = null; #region set email recipients { ObjectParameter[] parameters = new ObjectParameter[1]; parameters[0] = new ObjectParameter("InvoiceNumber", invoiceNumber); List<Models.EmailAddress> emailList = _db.ExecuteFunction<Models.EmailAddress>("uspGetEmailAddress", parameters).ToList<Models.EmailAddress>(); if(!string.IsNullOrEmpty(emailList[0].Email.ToString())) recipient = emailList[0].Email.ToString().Trim(); else recipient = " "; email.Recipients.Add(recipient); } #endregion //email subject email.Subject = "Invoice # " + invoiceNumber; #region set email Text { Models.EmailText emailText = _db.ExecuteFunction<Models.EmailText>("uspEmailText").SingleOrDefault(); messageBody = emailText.EmailTextLine1.ToString().Trim() + "\n\n\n\n\n\n\n\n\n"; messageBody += emailText.EmailTextLine2.ToString().Trim() + "\n"; messageBody += emailText.EmailTextLine3.ToString().Trim(); email.Body = messageBody; } #endregion #region email attachment { string fileName = invoiceNumber.Trim(); string filePath = HostingEnvironment.MapPath("~/Content/reports/"); filePath = filePath + fileName + ".pdf"; fileName += ".pdf"; int iPosition = (int)email.Body.Length + 1; int iAttachType = (int)Outlook.OlAttachmentType.olByValue; Outlook.Attachment oAttach = email.Attachments.Add(filePath, iAttachType, iPosition, fileName); } #endregion email.Display(); //uncomment below line to SendAutomatedEmail emails atomaticallly //((Outlook.MailItem)email).Send(); } catch (Exception e) { } }
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom) { try { _outlookApplication = new Outlook.Application(null, application); NetOffice.OutlookSecurity.Suppress.Enabled = true; } catch (Exception ex) { string message = string.Format("An error occured.{0}{0}{1}", Environment.NewLine, ex.Message); MessageBox.Show(message, "OPENERP-OnConnection", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void CreateOutlookAppointments() { var a = new Outlook.Application(); Outlook.AppointmentItem appointment = (Outlook.AppointmentItem)a.CreateItem(Outlook.OlItemType.olAppointmentItem); appointment.Subject = "Feierabend"; appointment.Start = DateTime.Now; appointment.End = appointment.Start.Date.AddDays(1); appointment.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh; appointment.ReminderMinutesBeforeStart = 15; appointment.ReminderSet = true; appointment.Save(); }
private void Button_Click_1(object sender, RoutedEventArgs e) { // google form for Curry // outlook Microsoft.Office.Interop.Outlook.Application otApp = new Outlook.Application(); // create outlook object Outlook.MailItem otMsg = (Outlook.MailItem)otApp.CreateItem(Outlook.OlItemType.olMailItem); // Create mail object Outlook.Recipient otRecip = (Outlook.Recipient)otMsg.Recipients.Add(EmailUrl); otRecip.Resolve(); // validate recipient address otMsg.Subject = "Test Subject"; otMsg.Body = "Text Message"; String sSource = AppDomain.CurrentDomain.BaseDirectory + "Test.txt"; }
Outlook.Application GetApplicationObject() { Outlook.Application application = null; // Check whether there is an Outlook process running. if (Process.GetProcessesByName("OUTLOOK").Count() > 0) { // If so, use the GetActiveObject method to obtain the process and cast it to an Application object. Or close Outlook to open a new instance with a desired profile application = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application; //!! Check if the application is using the right profile - close & reopen if necessary } else { // If not, create a new instance of Outlook and log on to the default profile.; application = new Outlook.Application(); Outlook.NameSpace nameSpace = application.GetNamespace("MAPI"); nameSpace.Logon("profilename", "", Missing.Value, Missing.Value); nameSpace = null; } // Return the Outlook Application object. return(application); }
//Tentative de connexion à Outlook public void tryHook() { while (true) { if (Process.GetProcessesByName("outlook").Length == 0) { startWatch.WaitForNextEvent(); } try { this.outlook = new Outlook.ApplicationClass(); this.outlook.ItemContextMenuDisplay += new Outlook.ApplicationEvents_11_ItemContextMenuDisplayEventHandler(addEntrytoContextMenu); } catch (Exception e) { MessageBox.Show(e.ToString()); } stopWatch.WaitForNextEvent(); Marshal.FinalReleaseComObject(this.outlook); this.outlook = null; } }
void extract(out String s1, out String s2, out String s3) { String s1 = String.Empty, s2 = String.Empty, s3 = String.Empty; String Body, address, subject; Outlook._Application oApp = new Outlook.Application(); if (oApp.ActiveExplorer().Selection.Count > 0) { Object selObject = oApp.ActiveExplorer().Selection[1]; if (selObject is Outlook.MailItem) { Outlook.MailItem mailItem = (selObject as Outlook.MailItem); subject = mailItem.Subject; address = mailItem.SenderEmailAddress; Body = mailItem.Body; s1 = Body; s2 = address; s3 = subject; } } }
public int countMail() { /* * * Gives the number of selected mail. * returns: Number of selected mail. * */ cnt_mail = 0; Outlook.Application app = _outlookApplication; //app = new Microsoft.Office.Interop.Outlook.Application(); try { cnt_mail = app.ActiveExplorer().Selection.Count; } catch (Exception) { return(0); } return(cnt_mail); }
public void SendMail(string args) { try { var oApp = new Outlook.Application(); var oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); var oRecip = (Outlook.Recipient)oMsg.Recipients.Add("*****@*****.**"); oRecip.Resolve(); oMsg.Subject = "Deskstop Standards: Required Items"; oMsg.Body = body oMsg.Display(true); oMsg.Save(); oMsg.Send(); oRecip = null; oMsg = null; oApp = null; } catch (Exception e) { Console.WriteLine("{problem with email execution} Exception caught: ", e); } return; }
public Form1(Outlook.Application _app) { App = _app; InitializeComponent(); }
public void OnStartupComplete(ref System.Array custom) { //----------------------------------------------------------------------------------------------------------------------------------------------------- /* /* * * When outlook is opened it loads a Menu if Outlook plugin is installed. * OpenERP - > Push, Partner ,Documents, Configuration * #1# */ Outlook.Application app = _outlookApplication; try { object omissing = System.Reflection.Missing.Value; menuBar = app.ActiveExplorer().CommandBars.ActiveMenuBar; ConfigManager config = new ConfigManager(); config.LoadConfigurationSetting(); OpenERPOutlookPlugin openerp_outlook = Cache.OpenERPOutlookPlugin; OpenERPConnect openerp_connect = openerp_outlook.Connection; try { if (openerp_connect.URL != null && openerp_connect.DBName != null && openerp_connect.UserId != null && openerp_connect.pswrd != "") { string decodpwd = Tools.DecryptB64Pwd(openerp_connect.pswrd); openerp_connect.Login(openerp_connect.DBName, openerp_connect.UserId, decodpwd); } } catch (Exception) { //just shallow exception } newMenuBar = (Office.CommandBarPopup)menuBar.Controls.Add(MsoControlType.msoControlPopup, omissing, omissing, omissing, true); if (newMenuBar != null) { newMenuBar.Caption = "OpenERP"; newMenuBar.Tag = "My"; btn_open_partner = (Office.CommandBarButton)newMenuBar.Controls.Add(MsoControlType.msoControlButton, omissing, omissing, 1, true); btn_open_partner.Style = MsoButtonStyle.msoButtonIconAndCaption; btn_open_partner.Caption = "Contact"; //Face ID will use to show the ICON in the left side of the menu. btn_open_partner.FaceId = 3710; newMenuBar.Visible = true; btn_open_partner.ClickEvent += new Office.CommandBarButton_ClickEventHandler(this.btn_open_partner_Click); //Core._CommandBarButtonEvents_ClickEventHandler(this.btn_open_partner_Click); btn_open_document = (Office.CommandBarButton)newMenuBar.Controls.Add(MsoControlType.msoControlButton, omissing, omissing, 2, true); btn_open_document.Style = MsoButtonStyle.msoButtonIconAndCaption; btn_open_document.Caption = "Documents"; //Face ID will use to show the ICON in the left side of the menu. btn_open_document.FaceId = 258; newMenuBar.Visible = true; btn_open_document.ClickEvent += new Office.CommandBarButton_ClickEventHandler(this.btn_open_document_Click); btn_open_configuration_form = (Office.CommandBarButton)newMenuBar.Controls.Add(MsoControlType.msoControlButton, omissing, omissing, 3, true); btn_open_configuration_form.Style = MsoButtonStyle.msoButtonIconAndCaption; btn_open_configuration_form.Caption = "Configuration"; //Face ID will use to show the ICON in the left side of the menu. btn_open_configuration_form.FaceId = 5644; newMenuBar.Visible = true; btn_open_configuration_form.ClickEvent += new Office.CommandBarButton_ClickEventHandler(this.btn_open_configuration_form_Click); } } catch (Exception ex) { string message = string.Format("An error occured.{0}{0}{1}", Environment.NewLine, ex.Message); MessageBox.Show(message, "OPENERP-Initialize menu", MessageBoxButtons.OK, MessageBoxIcon.Error); } }