void ICommand.Execute(object parameter) { var window = parameter as Window; var message = _viewModel.MessageText; var devEmail = _viewModel.ProblemTask.Owner.Email; var outlookApp = new OutlookApp(); string err; var mail = new MailToSend { MailBody = message, MailSubject = _viewModel.ProblemTask.Name + " Problem." }; mail.ToReceiverList.Add(devEmail); if (RunTimeContext.Context.CurrentUser.Manager != null) { mail.CCReceiverList.Add(RunTimeContext.Context.CurrentUser.Manager.Email); } OutlookUtil.CreateAndSendMail(outlookApp, mail, out err); MessageBox.Show("The email was sent successfully!"); if (window != null) { window.Close(); } }
public void StartIssueSenderJob() { string errorMsg = string.Empty; string mailBody = string.Empty; string subject = string.Empty; bool isIssueFileExist = false; List <string> attachedFileList = GetAttachedFileList(out isIssueFileExist); if (isIssueFileExist) { mailBody = @"Dear All , There are one file for CBBC and 2 files for further issue today. Should you have any questions, please feel free to contact me. "; } else { mailBody = @"Dear All , There are one file for CBBC and no files for further issue today. Should you have any questions, please feel free to contact me. "; } subject = "Daily files from East Asis " + MiscUtil.ParseDateTimeWithBlank(DateTime.Now) + " (HONG KONG)"; using (OutlookApp app = new OutlookApp()) { OutlookUtil.CreateAndSendMail(app, attachedFileList, subject, configObj.ISSUE_SENDER_CONFIG.TO_TYPE_RECIPIENTS, configObj.ISSUE_SENDER_CONFIG.CC_TYPE_RECIPIENTS, mailBody, out errorMsg); } }
public void TestSendMail() { for (int i = 0; i < 1; i++) { string content = "附件为" + DateTime.Now.ToString("yyyyMMdd") + " 数据,请查阅,谢谢!"; content = "各收件人,<br/>\r\n<br/>请重点关注以下内容:<br/>\r\n<br/>" + content + "<br/>\r\n<br/> <br/>\r\n<br/>此邮件为系统自动邮件通知,请不要直接进行回复!谢谢。!"; content = content + "<br/>\r\n<br/>"; using (OutlookApp outlookApp = new OutlookApp(false)) { outlookApp.NewEmail(); outlookApp.SetMailSendTo("*****@*****.**"); outlookApp.SetCC("*****@*****.**"); outlookApp.SetMailSubject(DateTime.Now.ToString()); outlookApp.SetMailBodyFormat(OlBodyFormat.olFormatHTML); outlookApp.SetMailHTMLBody(content); //outlookApp.SetMailAddAttachments(@"C:\Publish\OAMOCR.Wpf.zip"); //outlookApp.SetMailAddAttachments(@"C:\Publish\OAMOCR.Wpf - Copy.zip"); //outlookApp.SetMailVotingOptions("Yes;No;"); outlookApp.ShowEmail(); } } }
static void Main(string[] args) { Outlook.Application OutlookApp = null; if (System.Diagnostics.Process.GetProcessesByName("OUTLOOK").Length > 0) { // If so, use the GetActiveObject method to obtain the process and cast it to an Application object. OutlookApp = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application; } else { // If not, create a new instance of Outlook and log on to the default profile. OutlookApp = new Outlook.Application(); } string defaultProfile = OutlookApp.DefaultProfileName; Outlook.NameSpace nameSpace = OutlookApp.GetNamespace("MAPI"); nameSpace.Logon(Profile: "", Password: "", ShowDialog: Missing.Value, NewSession: Missing.Value); var OutlookSession = OutlookApp.Session; Stores stores = nameSpace.Stores; //Task.Factory.StartNew(() => EnumerateFolderItems(stores, "2007-00-00", "2007-00-00")); EnumerateFolderItems(stores, "2007-00-00", "2007-00-00"); //EnumerateStores(stores); //DeleteEmptyFolders(stores); //for (int i = 0; i < 10; i++) //{ // EnumerateItems(stores); //} DeleteEmptyFolders(stores); //CreateSortStores(OutlookApp); //NameSortStores(OutlookApp); }
/// <summary> /// Constructor /// </summary> public MainWindow() { InitializeComponent(); _outlook = new OutlookApp(); GetOutlookTemplates(); FormIsReady(); }
public void StartAdditionalRicSenderJob() { string errorMsg = string.Empty; //FM READY_2 CBBC 15 WARRANTS 1 NAME CHANGE 2 PTs.msg string subject = "FM READY_ "; subject += GetAdditionalRicNumStr(configObj.CBBC_FILE_PATH); subject += " CBBC "; subject += GetAdditionalRicNumStr(configObj.WARRANT_FILE_PATH); subject += " WARRANTS "; subject += configObj.NAME_CHANGE_INFO; using (OutlookApp app = new OutlookApp()) { OutlookUtil.CreateAndSendMail(app, subject, configObj.TO_TYPE_RECIPIENTS, configObj.CC_TYPE_RECIPIENTS, "", out errorMsg); } Logger.Log(errorMsg); }
//Send mail with CB Announcement text file attached. private void sendMail() { string errMsg = string.Empty; List <string> fileList = new List <string>(); string mailSuj = "TW CB PRICE " + DateTime.Now.ToString("ddMMMyy").ToUpper(); string mailBody = @"Hi, Grateful your help to insert attached file for real-time data correction asap. Thank you in advance. Regards"; if (fileList.Count != 0) { using (OutlookApp app = new OutlookApp()) { OutlookUtil.CreateAndSendMail(app, cbAnnouncementFileList, mailSuj, configObj.TO_TYPE_RECIPIENTS, configObj.CC_TYPE_RECIPIENTS, mailBody, out errMsg); } } }
public void StartFMSenderJob() { string errorMsg = string.Empty; List <string> attachedFileList = new List <string>(); string subject = "HKFM_"; subject += MiscUtil.ParseDateTime(DateTime.Now); subject += "_2"; string mailBody = @"Hi, Please find the FM for today in the attached folder. Should you have any questions, please feel free to contact me. "; string attachedFile = GetFMFileZip(configObj.FM_SENDER_CONFIG.FM_FILE_DIR); attachedFileList.Add(attachedFile); using (OutlookApp app = new OutlookApp()) { OutlookUtil.CreateAndSendMail(app, attachedFileList, subject, configObj.FM_SENDER_CONFIG.TO_TYPE_RECIPIENTS, configObj.FM_SENDER_CONFIG.CC_TYPE_RECIPIENTS, mailBody, out errorMsg); } }
public void StartDelistSenderJob() { string errorMsg = string.Empty; string subject = "HKFM_"; subject += ParseDateTime(GetNextBusinessDay(configObj.HOLIDAY_COUNT)); subject += "_1"; string mailBody = @"Dear all, Please find attached today’s last minute FM. Should you have any questions, please feel free to contact me."; List <string> attachedFileList = GetDelistFileList(configObj.LAST_DELIST_FILE_DIR); using (OutlookApp app = new OutlookApp()) { OutlookUtil.CreateAndSendMail(app, attachedFileList, subject, configObj.TO_TYPE_RECIPIENTS, configObj.CC_TYPE_RECIPIENTS, mailBody, out errorMsg); } Logger.Log(errorMsg); }
/// <summary> Returns the type of Office Application that is hosting the VBE. </summary> public static IHostApplication HostApplication(this IVBE vbe) { var host = Path.GetFileName(System.Windows.Forms.Application.ExecutablePath).ToUpperInvariant(); //This needs the VBE as a ctor argument. if (host.Equals("SLDWORKS.EXE")) { return(new SolidWorksApp(vbe)); } //The rest don't. if (HostAppMap.ContainsKey(host)) { return((IHostApplication)Activator.CreateInstance(HostAppMap[host])); } //Guessing the above will work like 99.9999% of the time for supported applications. var project = vbe.ActiveVBProject; { if (project.IsWrappingNullReference) { const int ctlViewHost = 106; var commandBars = vbe.CommandBars; var hostAppControl = commandBars.FindControl(ControlType.Button, ctlViewHost); { IHostApplication result; if (hostAppControl.IsWrappingNullReference) { result = null; } else { switch (hostAppControl.Caption) { case "Microsoft Excel": result = new ExcelApp(); break; case "Microsoft Access": result = new AccessApp(); break; case "Microsoft Word": result = new WordApp(); break; case "Microsoft PowerPoint": result = new PowerPointApp(vbe); break; case "Microsoft Outlook": result = new OutlookApp(); break; case "Microsoft Project": result = new ProjectApp(); break; case "Microsoft Publisher": result = new PublisherApp(); break; case "Microsoft Visio": result = new VisioApp(); break; case "AutoCAD": result = new AutoCADApp(); break; case "CorelDRAW": result = new CorelDRAWApp(); break; case "SolidWorks": result = new SolidWorksApp(vbe); break; default: result = null; break; } } return(result); } } var references = project.References; { foreach (var reference in references.Where(reference => (reference.IsBuiltIn && reference.Name != "VBA") || (reference.Name == "AutoCAD"))) { switch (reference.Name) { case "Excel": return(new ExcelApp(vbe)); case "Access": return(new AccessApp()); case "Word": return(new WordApp(vbe)); case "PowerPoint": return(new PowerPointApp(vbe)); case "Outlook": return(new OutlookApp()); case "MSProject": return(new ProjectApp()); case "Publisher": return(new PublisherApp()); case "Visio": return(new VisioApp()); case "AutoCAD": return(new AutoCADApp()); case "CorelDRAW": return(new CorelDRAWApp(vbe)); case "SolidWorks": return(new SolidWorksApp(vbe)); } } } } return(null); }