コード例 #1
0
 protected void ButtonSendMail_Click(object sender, EventArgs e)
 {
     try
     {
         List <string> lstAllRecipients = new List <string>();
         //Below is hardcoded - can be replaced with db data
         lstAllRecipients.Add("*****@*****.**");
         lstAllRecipients.Add("*****@*****.**");
         Outlook.Application outlookApp = new Outlook.Application();
         Outlook._MailItem   oMailItem  = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
         Outlook.Inspector   oInspector = oMailItem.GetInspector;
         // Thread.Sleep(10000);
         // Recipient
         Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients;
         foreach (String recipient in lstAllRecipients)
         {
             Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(recipient);
             oRecip.Resolve();
         }
         //Add CC
         Outlook.Recipient oCCRecip = oRecips.Add("*****@*****.**");
         oCCRecip.Type = (int)Outlook.OlMailRecipientType.olCC;
         oCCRecip.Resolve();
         //Add Subject
         oMailItem.Subject = "Test Mail";
         // body, bcc etc...
         //Display the mailbox
         oMailItem.Display(true);
     }
     catch (Exception objEx)
     {
         Response.Write(objEx.ToString());
     }
 }
コード例 #2
0
        /// <summary>
        /// 送信先の表示名と表示名とメールアドレスを対応させるDictionary。(Outlookの仕様上、表示名にメールアドレスが含まれない事がある。)
        /// </summary>
        /// <param name="mail"></param>
        private void MakeDisplayNameAndRecipient(Outlook._MailItem mail)
        {
            foreach (Outlook.Recipient recip in mail.Recipients)
            {
                // Exchangeの連絡先に登録された情報を取得。
                var exchangeUser = recip.AddressEntry.GetExchangeUser();

                // Exchangeの配布リスト(ML)として登録された情報を取得。
                var exchangeDistributionList = recip.AddressEntry.GetExchangeDistributionList();

                // ローカルの連絡先に登録された情報を取得。
                var registeredUser = recip.AddressEntry.GetContact();

                // 登録されたメールアドレスの場合、登録名のみが表示されるため、メールアドレスと共に表示されるよう表示用テキストを生成。
                var nameAndMailAddress = exchangeUser != null
                        ? exchangeUser.Name + $@" ({exchangeUser.PrimarySmtpAddress})" :
                                         exchangeDistributionList != null
                        ? exchangeDistributionList.Name + $@" ({exchangeDistributionList.PrimarySmtpAddress})" :
                                         registeredUser != null
                        ? recip.Name + $@" ({recip.Address})"
                        : recip.Address;

                _displayNameAndRecipient[recip.Name] = nameAndMailAddress;
            }
        }
コード例 #3
0
        public void SendMail(string Subject, string ToAddress, string CCAddress, string Body, string Attachment, bool RequestReadReceipt)
        {
            Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

            oMailItem.Recipients.Add(ToAddress);
            oMailItem.CC = CCAddress;

            oMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatPlain;
            oMailItem.Subject    = Subject;
            oMailItem.Body       = Body;
            //oMailItem.SaveSentMessageFolder = oSentItemsFolder;
            oMailItem.ReadReceiptRequested = RequestReadReceipt;
            oMailItem.Attachments.Add(Attachment);

            if (oMailItem.Recipients.ResolveAll())
            {
                if (Mode == "LIVE")
                {
                    oMailItem.Send();
                }
                else
                {
                    oMailItem.Save();
                }
            }
            else
            {
                throw new ApplicationException("Problem with recipient " + ToAddress);
            }
        }
コード例 #4
0
        public static void SendEmailToSupport(Exception catchedException)
        {
            try
            {
                LoginInfo loginInfo = LoginInfo.GetInstance();

                Outlook.Application outlookApp = GetApplicationObject();
                Outlook._MailItem   mailItem   = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
                mailItem.Subject = loginInfo.UserName + "---ERROR: " + catchedException.Message;
                mailItem.Body    = catchedException.ToString();

                Outlook.Recipient recipient = (Outlook.Recipient)mailItem.Recipients.Add("*****@*****.**");
                recipient.Resolve();

                mailItem.Send();

                recipient  = null;
                mailItem   = null;
                outlookApp = null;
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
コード例 #5
0
 /*
  * Uses the email and opens an outlook window with subject, body, to address, and attachments
  * filled in.
  */
 public void openOutlookWindow()
 {
     try
     {
         Outlook.Application oApp      = new Outlook.Application();
         Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
         oMailItem.To      = toAddress;
         oMailItem.Subject = subject;
         oMailItem.Body    = body;
         oMailItem.CC      = cc;
         if (attach1 != null)
         {
             oMailItem.Attachments.Add(attach1);
         }
         if (attach2 != null)
         {
             oMailItem.Attachments.Add(attach2);
         }
         oMailItem.Display(true);
         oApp.ActiveWindow();
     }catch (System.Exception ex)
     {
         MessageBox.Show("Outlook Error: " + ex.Message, "Error with outlook window", MessageBoxButtons.OK, MessageBoxIcon.Error);
         Console.WriteLine("Error with outlook." + ex.Message);
     }
 }
コード例 #6
0
ファイル: Mail.cs プロジェクト: zergmk2/autotester-1
        /* void CreateNewMail()
         * Init parameters, prepare to send a new mail.
         */
        private void CreateNewMail()
        {
            try
            {
                if (this._serverType == MailServerType.SMTP)
                {
                    _netMail = new MailMessage();

                    _netMail.IsBodyHtml = _mailType == MailType.HTML;

                    if (_smtpServer == null)
                    {
                        _smtpServer = new SmtpClient(_smtpServerAddr);
                    }
                }
                else
                {
#if OUTLOOK
                    if (!_logged)
                    {
                        _oNS.Logon(null, null, false, false);
                        _logged = true;
                    }

                    _oMsg = (Outlook.MailItem)_oApp.CreateItem(Outlook.OlItemType.olMailItem);
#endif
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Can not create a new mail: " + ex.ToString());
            }
        }
コード例 #7
0
ファイル: Mail.cs プロジェクト: zergmk2/autotester-1
        public void Dispose()
        {
            try
            {
                if (_serverType == MailServerType.SMTP)
                {
                    if (_netMail != null)
                    {
                        _netMail.Dispose();
                        _netMail = null;
                    }
                }
                else
                {
#if OUTLOOK
                    // Log off.
                    _oNS.Logoff();

                    // Clean up.
                    _oRecip  = null;
                    _oRecips = null;
                    _oMsg    = null;
                    _oNS     = null;
                    _oApp    = null;
#endif
                }

                GC.Collect();

                GC.SuppressFinalize(this);
            }
            catch
            {
            }
        }
コード例 #8
0
        public void OnSendList(Office.Core.IRibbonControl control)
        {
            if (control != null)
            {
                try
                {
                    Outlook.Inspector inspector =
                        (Outlook.Inspector)control.Context;
                    String coffeeText = GetTextFromTaskPane(inspector);

                    // Create a new email from the input parameters, and send it.
                    Outlook._MailItem mi =
                        (Outlook._MailItem)
                        Globals.ThisAddIn.Application.CreateItem(
                            Outlook.OlItemType.olMailItem);
                    mi.Subject = _orderName;
                    mi.Body    = coffeeText;
                    mi.To      = _mailAddressee;
                    mi.Send();

                    // Update the count of orders in the form region.
                    UserInterfaceContainer uiContainer =
                        Globals.ThisAddIn._uiElements.GetUIContainerForInspector(
                            inspector);
                    CultureInfo cultureInfo = new CultureInfo("en-us");
                    uiContainer.FormRegionControls.SetControlText(
                        _ordersTextBoxName, (++_orderCount).ToString(cultureInfo));
                }
                catch (COMException ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// 登録された名称とドメインから、宛先候補ではないアドレスが宛先に含まれている場合に、警告を表示する。
        /// </summary>
        /// <param name="mail"></param>
        private void CheckMailbodyAndRecipient(Outlook._MailItem mail)
        {
            //Load NameAndDomainsList
            var readCsv            = new ReadAndWriteCsv("NameAndDomains.csv");
            var nameAndDomainsList = readCsv.ReadCsv <NameAndDomains>(readCsv.ParseCsv <NameAndDomainsMap>());

            //メールの本文中に、登録された名称があるか確認。
            var recipientCandidateDomains = (from nameAnddomain in nameAndDomainsList where mail.Body.Contains(nameAnddomain.Name) select nameAnddomain.Domain).ToList();

            //登録された名称かつ本文中に登場した名称以外のドメインが宛先に含まれている場合、警告を表示。
            //送信先の候補が見つからない場合、何もしない。(見つからない場合の方が多いため、警告ばかりになってしまう。)
            if (recipientCandidateDomains.Count != 0)
            {
                foreach (var recipients in _displayNameAndRecipient)
                {
                    if (!recipientCandidateDomains.Any(
                            domains => domains.Equals(
                                recipients.Value.Substring(recipients.Value.IndexOf("@", StringComparison.Ordinal)))))
                    {
                        //送信者ドメインは警告対象外。
                        if (!recipients.Value.Contains(
                                mail.SendUsingAccount.SmtpAddress.Substring(
                                    mail.SendUsingAccount.SmtpAddress.IndexOf("@", StringComparison.Ordinal))))
                        {
                            AlertBox.Items.Add(recipients.Key + @" : このアドレスは意図した宛先とは無関係の可能性があります!");
                            AlertBox.ColorFlag.Add(true);
                        }
                    }
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Given the mail item we try and get the email address of the sender.
        /// </summary>
        /// <param name="mail"></param>
        /// <returns>string or null if the address does not exist.</returns>
        private static string GetSmtpAddressForSender(Outlook._MailItem mail)
        {
            if (mail == null)
            {
                throw new ArgumentNullException(nameof(mail));
            }

            if (mail.SenderEmailType != "EX")
            {
                return(mail.SenderEmailAddress);
            }

            var sender = mail.Sender;

            if (sender == null)
            {
                return(null);
            }

            //Now we have an AddressEntry representing the Sender
            if (sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry ||
                sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
            {
                //Use the ExchangeUser object PrimarySMTPAddress
                var exchUser = sender.GetExchangeUser();
                if (exchUser != null)
                {
                    return(exchUser.PrimarySmtpAddress);
                }
            }

            const string prSmtpAddress = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";

            return(sender.PropertyAccessor.GetProperty(prSmtpAddress) as string);
        }
コード例 #11
0
ファイル: OutlookClass.cs プロジェクト: hjgode/mail_grabber
        public string findLicenseMails()
        {
            StringBuilder sb = new StringBuilder();

            Microsoft.Office.Interop.Outlook._MailItem InboxMailItem = null;
            Microsoft.Office.Interop.Outlook.Items     oItems        = MyInbox.Items;
            string Query = "[Subject] contains 'Your license order'";

            //string filter = "urn:schemas:mailheader:subject LIKE '%" + wordInSubject + "%'";

            InboxMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oItems.Find(Query);
            while (InboxMailItem != null)
            {
                //ListViewItem myItem = lvwMails.Items.Add(InboxMailItem.SenderName);
                //myItem.SubItems.Add(InboxMailItem.Subject);
                sb.Append(InboxMailItem.SenderName + ": ");
                sb.Append(InboxMailItem.Subject + "\r\n");
                string AttachmentNames = string.Empty;
                foreach (Microsoft.Office.Interop.Outlook.Attachment item in InboxMailItem.Attachments)
                {
                    AttachmentNames += item.DisplayName;
                    sb.Append("\t" + item.DisplayName + "\r\n");
                    //item.SaveAsFile(this.GetAttachmentPath(item.FileName, "c:\\test\\attachments\\"));
                }
                //myItem.SubItems.Add(AttachmentNames);
                //InboxMailItem.Delete();
                InboxMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oItems.FindNext();
            }
            return(sb.ToString());
        }
コード例 #12
0
ファイル: AutoReplyEmail.cs プロジェクト: Br3nda/sfdocsamples
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext context)
        {
            // Create an Outlook Application object.
            Outlook.Application outlookApp = new Outlook.Application();

            Outlook._MailItem oMailItem = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
            oMailItem.To      = outlookApp.Session.CurrentUser.Address;
            oMailItem.Subject = "Auto-Reply";
            oMailItem.Body    = "Out of Office";

            //adds it to the outbox
            if (this.Parent.Parent is ParallelActivity)
            {
                if ((this.Parent.Parent.Parent.Activities[1] as DummyActivity).TitleProperty != "")
                {
                    MessageBox.Show("Process Auto-Reply for Email");
                    oMailItem.Send();
                }
            }
            else if (this.Parent.Parent is SequentialWorkflowActivity)
            {
                if ((this.Parent.Parent.Activities[1] as DummyActivity).TitleProperty != "")
                {
                    MessageBox.Show("Process Auto-Reply for Email");
                    oMailItem.Send();
                }
            }
            return(ActivityExecutionStatus.Closed);
        }
コード例 #13
0
        public static Boolean SendOutlookMail(string recipient, string subject, string body)
        {
            try
            {
                Outlook.Application outlookApp = new Outlook.Application();
                Outlook._MailItem   oMailItem  = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
                Outlook.Inspector   oInspector = oMailItem.GetInspector;

                Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients;
                Outlook.Recipient  oRecip  = (Outlook.Recipient)oRecips.Add(recipient);
                oRecip.Resolve();

                if (subject != "")
                {
                    oMailItem.Subject = subject;
                }
                if (body != "")
                {
                    oMailItem.Body = body;
                }
                oMailItem.Display(true);
                return(true);
            }
            catch (Exception objEx)
            {
                MessageBox.Show(objEx.ToString());
                return(false);
            }
        }
コード例 #14
0
ファイル: cEmail.cs プロジェクト: rafaelcolvara/NavEventos
        public void Monta(int pIdEvento, string pAssunto)
        {
            lock (cGlobal.bloqueadorThread)
            {
                int idTipoEvento             = 0;
                previa_Cronograma pc         = new previa_Cronograma();
                Outlook._MailItem oMailItem  = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
                Outlook.Inspector oInspector = oMailItem.GetInspector;

                Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients;

                using (DataSet dsmsg = pc.retorna_mensagem_email(pIdEvento))
                {
                    oMailItem.Subject = dsmsg.Tables["MsgEmail"].Rows[0]["Mensagem"].ToString();
                    idTipoEvento      = Convert.ToInt32(dsmsg.Tables["MsgEmail"].Rows[0]["ID_TIPO_EVENTO"].ToString());
                }

                #region MONTA CORPO DO E-MAIL
                pAssunto      += oMailItem.Subject;
                oMailItem.Body = pAssunto;

                #endregion

                oMailItem.Display(true);

                if (pc.exclui_mensagem_email(pIdEvento, idTipoEvento) < 1)
                {
                    throw new Exception("Não foi possivel atualizar mensagem. Atenção no formato do email");
                }
            }
        }
コード例 #15
0
        /// <summary>
        /// メール送信の確認画面を表示。
        /// </summary>
        /// <param name="mail">送信するメールアイテム</param>
        public CheckList GenerateCheckListFromMail(Outlook._MailItem mail)
        {
            //This methods must run first.
            GetGeneralMailInfomation(mail);

            MakeDisplayNameAndRecipient(mail);

            CheckForgotAttach(mail);

            CheckKeyword();

            AutoAddCcAndBcc(mail);

            //TODO Temporary processing. It will be improved.
            MakeDisplayNameAndRecipient(mail);

            GetRecipient();

            GetAttachmentsInfomation(mail);

            CheckMailbodyAndRecipient();

            CountRecipientExternalDomains();

            _checkList.DeferredMinutes = CalcDeferredMinutes();

            return(_checkList);
        }
コード例 #16
0
        /// <summary>
        /// メール送信の確認画面を表示。
        /// </summary>
        /// <param name="mail">送信するメールアイテム</param>
        /// <param name="generalSetting">一般設定</param>
        public CheckList GenerateCheckListFromMail(Outlook._MailItem mail, GeneralSetting generalSetting)
        {
            //This methods must run first.
            GetGeneralMailInformation(in mail);

            //This methods must run second.
            GetAttachmentsInformation(in mail, generalSetting.IsNotTreatedAsAttachmentsAtHtmlEmbeddedFiles);

            MakeDisplayNameAndRecipient(mail.Recipients, generalSetting);

            CheckForgotAttach(in mail);

            CheckKeyword();

            AutoAddCcAndBcc(mail, generalSetting);

            GetRecipient();

            CheckMailBodyAndRecipient();

            _checkList.RecipientExternalDomainNum = CountRecipientExternalDomains();

            _checkList.DeferredMinutes = CalcDeferredMinutes();

            return(_checkList);
        }
コード例 #17
0
        public void Button_Click(Office.IRibbonControl control)
        {
            try
            {
                Outlook.Recipient  recipient  = null;
                Outlook.Recipients recipients = null;

                Outlook.Application application = new Outlook.Application();
                Outlook.Explorer    explorer    = application.ActiveExplorer();
                Outlook.Inspector   inspector   = application.ActiveInspector();
                inspector.Activate();
                Outlook._MailItem mailItem = inspector.CurrentItem;

                //Outlook.Application outlookApplication = new Outlook.Application();
                //Outlook.MailItem mail = (Outlook.MailItem)outlookApplication.ActiveInspector().CurrentItem;

                if (mailItem != null)
                {
                    recipients = mailItem.Recipients;
                    recipients.ResolveAll();
                    String       StrR            = "";
                    const string PR_SMTP_ADDRESS =
                        "http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
                    foreach (Outlook.Recipient recip in recipients)
                    {
                        Outlook.PropertyAccessor pa = recip.PropertyAccessor;
                        string smtpAddress          =
                            pa.GetProperty(PR_SMTP_ADDRESS).ToString();

                        string[] strsplit = smtpAddress.Split('@');
                        if (!StrR.Contains(strsplit[1]))
                        {
                            StrR += strsplit[1] + Environment.NewLine;
                        }
                    }
                    if (StrR != string.Empty)
                    {
                        MyMessageBox ObjMyMessageBox = new MyMessageBox();
                        ObjMyMessageBox.ShowBox(StrR);
                    }



                    //recipient.Resolve();
                    //                DialogResult result = MessageBox.Show("Are you sure you want to send emails to the following domains " + StrR, "Varify Domains ",
                    //MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    //                if (result == DialogResult.Yes)
                    //                {
                    //                    //code for Yes
                    //                }
                    //                else
                    //                {

                    //                }
                }
            }
            catch (Exception ex)
            {
            }
        }
コード例 #18
0
        /// <summary>
        /// Get the email address of recepients.
        /// @see https://msdn.microsoft.com/en-us/library/office/ff868695.aspx
        /// </summary>
        /// <param name="mail"></param>
        private static List <string> GetSmtpAddressForRecipients(Outlook._MailItem mail)
        {
            var recips    = mail.Recipients;
            var addresses = new List <string>();

            foreach (Outlook.Recipient recipient in recips)
            {
                try
                {
                    try
                    {
                        addresses.Add(GetSmtpAddress(recipient));
                    }
                    catch
                    {
                        // try get the address
                        var email = recipient.Address;
                        if (!string.IsNullOrEmpty(email))
                        {
                            addresses.Add(email);
                        }
                    }
                }
                catch
                {
                    //  ignore
                }
            }
            return(addresses);
        }
コード例 #19
0
 /// <summary>
 /// Try and classify a mail assyncroniously.
 /// </summary>
 /// <param name="mailItem">The mail we want to classify.</param>
 /// <param name="id">the category we are setting it to.</param>
 /// <param name="weight">The classification weight we will be using.</param>
 /// <returns></returns>
 private async Task <Errors> ClassifyAsync(Outlook._MailItem mailItem, uint id, uint weight)
 {
     return(await ClassifyAsync(GetUniqueIdentifierString(mailItem),
                                GetStringFromMailItem(mailItem, _engine.Logger),
                                id,
                                weight).ConfigureAwait(false));
 }
コード例 #20
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            Outlook._MailItem a = null;
            var parent          = a.Parent;

            Outlook._Store store  = null;
            var            folder = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderJunk);
        }
コード例 #21
0
        /// <summary>
        /// Get the category for the document id.
        /// </summary>
        /// <param name="mailItem">the mail item we are looking for.</param>
        /// <returns>Category|null</returns>
        public Category GetCategoryFromMailItem(Outlook._MailItem mailItem)
        {
            // get the unique identifier
            var uniqueIdentifier = GetUniqueIdentifierString(mailItem);

            // then look for it in the engine.
            return(_engine.Categories.FindCategoryById(_engine.Categories.GetCategoryFromUniqueId(uniqueIdentifier)));
        }
コード例 #22
0
 /// <summary>
 /// ファイルの添付忘れを確認。
 /// </summary>
 /// <param name="mail"></param>
 private void CheckForgotAttach(Outlook._MailItem mail)
 {
     if (mail.Body.Contains("添付") && mail.Attachments.Count == 0)
     {
         AlertBox.Items.Add(@"本文中に 添付 という文言があるのに添付ファイルがありません。");
         AlertBox.ColorFlag.Add(false);
     }
 }
コード例 #23
0
        public void CreateEmail(DateTime time_period_start)
        {
            // Copy the excel sheet and rename properly
            var strCurrentFilePath     = Properties.Settings.Default.OutputDirectory + Properties.Settings.Default.OutputExcelFile;
            var file_type_dot_index    = Properties.Settings.Default.OutputExcelFile.LastIndexOf('.');
            var strOutputPathDirectory = Properties.Settings.Default.OutputDirectory;
            var strOutputPathFileName  = Properties.Settings.Default.Name + " - " +
                                         Properties.Settings.Default.OutputExcelFile.Substring(0, file_type_dot_index) + " (" +
                                         time_period_start.ToString(@"dd\-MM\-yy") + " - " +
                                         time_period_start.AddDays(14).ToString(@"dd\-MM\-yy") + ")" +
                                         Properties.Settings.Default.OutputExcelFile.Substring(file_type_dot_index);
            var strFullPath = strOutputPathDirectory + strOutputPathFileName;

            // Write data to excel spreadsheet
            XSSFWorkbook hssfwb;

            using (FileStream file = new FileStream(strCurrentFilePath, FileMode.Open, FileAccess.Read))
            {
                hssfwb = new XSSFWorkbook(file);
                file.Close();
            }

            using (FileStream file = new FileStream(strFullPath, FileMode.CreateNew, FileAccess.Write))
            {
                hssfwb.Write(file);
                file.Close();
            }

            // Create mail
            Outlook.Application oApp      = new Outlook.Application();
            Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
            oMailItem.To      = Properties.Settings.Default.EmailRecipient;
            oMailItem.Subject = "Timesheet - " + Properties.Settings.Default.Name;
            var output_body = Properties.Settings.Default.EmailBody.Replace("*NAME*", Properties.Settings.Default.Name);

            output_body = output_body.Replace("*DATES*", time_period_start.ToShortDateString() + " - " + time_period_start.AddDays(14).ToShortDateString());
            oMailItem.Attachments.Add(strFullPath, Outlook.OlAttachmentType.olByValue, 1, "Timesheet");
            oMailItem.Body = output_body;
            oMailItem.Display(true);

            // Save / Store a copy in /saved folder
            if (Properties.Settings.Default.SaveLocalCopy)
            {
                strOutputPathDirectory = Properties.Settings.Default.OutputDirectory + "Saved\\";
                strFullPath            = strOutputPathDirectory + strOutputPathFileName;
                System.IO.Directory.CreateDirectory(strOutputPathDirectory);

                using (FileStream file = new FileStream(strFullPath, FileMode.CreateNew, FileAccess.Write))
                {
                    hssfwb.Write(file);
                    file.Close();
                }
            }

            // Delete
            File.Delete(strFullPath);
        }
コード例 #24
0
 private void btnContact_Click(object sender, EventArgs e)
 {
     Outlook.Application oApp      = new Outlook.Application();
     Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
     oMailItem.To = "*****@*****.**";
     oMailItem.CC = "*****@*****.**";
     // body, bcc etc...
     oMailItem.Display(true);
 }
コード例 #25
0
        /// <summary>
        /// Try and categorise an email.
        /// </summary>
        /// <param name="mailItem">The mail item we are working with</param>
        /// <returns></returns>
        public async Task <CategorizeResponse> CategorizeAsync(Outlook._MailItem mailItem)
        {
            bool magnetWasUsed;
            var  categoryId = await Task.FromResult(Categorize(mailItem, out magnetWasUsed)).ConfigureAwait(false);

            return(new CategorizeResponse {
                CategoryId = categoryId, WasMagnetUsed = magnetWasUsed
            });
        }
コード例 #26
0
        private void btnEmail_Click(object sender, EventArgs e)
        {
            string body = "";
            List <RealTimePositionObject> AdrPositions   = new List <RealTimePositionObject>();
            List <RealTimePositionObject> HrdPositions   = new List <RealTimePositionObject>();
            List <RealTimePositionObject> OtherPositions = new List <RealTimePositionObject>();

            //generate the text
            LoadHeldUp();

            foreach (RealTimePositionObject r in HeldUpRealTimePositions)
            {
                //find positions with hedge data
                if (r.DtcActivity.Exists(d => d.ReasonCode == "260") || r.DtcActivity.Exists(d => d.ReasonCode == "261") ||
                    r.DtcActivity.Exists(d => d.ReasonCode == "270") || r.DtcActivity.Exists(d => d.ReasonCode == "271"))
                {
                    r.ContainsHedge = true;
                }

                if (r.TradeCategory.Contains("ADR"))
                {
                    AdrPositions.Add(r);
                }
                if (r.TradeCategory.Contains("HRD"))
                {
                    HrdPositions.Add(r);
                }
                if (!r.TradeCategory.Contains("HRD") && !r.TradeCategory.Contains("ADR"))
                {
                    OtherPositions.Add(r);
                }
            }

            AdrPositions.Sort((a1, a2) => a1.Ticker.CompareTo(a2.Ticker));
            HrdPositions.Sort((a1, a2) => a1.Ticker.CompareTo(a2.Ticker));
            OtherPositions.Sort((a1, a2) => a1.Ticker.CompareTo(a2.Ticker));

            body += "<br>ADR<br>";
            body += GenerateHtmlTable(AdrPositions);

            body += "<br>HRD<br>";
            body += GenerateHtmlTable(HrdPositions);

            body += "<br>OTHER<br>";
            body += GenerateHtmlTable(OtherPositions);

            Outlook.Application oApp      = new Outlook.Application();
            Outlook._MailItem   oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

            oMailItem.To         = "";
            oMailItem.Subject    = "Held Up Positions";
            oMailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
            oMailItem.HTMLBody   = body;

            oMailItem.Display(false);
        }
コード例 #27
0
        /// <summary>
        /// 添付ファイルとそのファイルサイズを取得し、チェックリストに追加する。
        /// </summary>
        /// <param name="mail"></param>
        private void GetAttachmentsInfomation(Outlook._MailItem mail)
        {
            if (mail.Attachments.Count == 0)
            {
                return;
            }

            for (var i = 0; i < mail.Attachments.Count; i++)
            {
                var fileSize = Math.Round(((double)mail.Attachments[i + 1].Size / 1024), 0, MidpointRounding.AwayFromZero).ToString("##,###") + "KB";

                //10Mbyte以上の添付ファイルは警告も表示。
                if (mail.Attachments[i + 1].Size >= 10485760)
                {
                    _checkList.Alerts.Add(new Alert {
                        AlertMessage = Resources.IsBigAttachedFile + $"[{mail.Attachments[i + 1].FileName}]", IsChecked = false, IsImportant = true, IsWhite = false
                    });
                }

                //一部の状態で添付ファイルのファイルタイプを取得できないため、それを回避。
                string fileType;
                try
                {
                    fileType = mail.Attachments[i + 1].FileName.Substring(mail.Attachments[i + 1].FileName.LastIndexOf(".", StringComparison.Ordinal));
                }
                catch (Exception)
                {
                    fileType = Resources.Unknown;
                }

                var isDangerous = false;

                //実行ファイル(.exe)を添付していたら警告を表示
                if (fileType == ".exe")
                {
                    _checkList.Alerts.Add(new Alert {
                        AlertMessage = Resources.IsAttachedExe + $"[{mail.Attachments[i + 1].FileName}]", IsChecked = false, IsImportant = true, IsWhite = false
                    });
                    isDangerous = true;
                }

                string attachmetName;
                try
                {
                    attachmetName = mail.Attachments[i + 1].FileName;
                }
                catch (Exception)
                {
                    attachmetName = Resources.Unknown;
                }

                _checkList.Attachments.Add(new Attachment {
                    FileName = attachmetName, FileSize = fileSize, FileType = fileType, IsTooBig = mail.Attachments[i + 1].Size >= 10485760, IsEncrypted = false, IsChecked = false, IsDangerous = isDangerous
                });
            }
        }
コード例 #28
0
 /// <summary>
 /// 添付ファイルとそのファイルサイズを取得し、画面に表示する。
 /// </summary>
 /// <param name="mail"></param>
 private void DrawAttachments(Outlook._MailItem mail)
 {
     if (mail.Attachments.Count != 0)
     {
         for (var i = 0; i < mail.Attachments.Count; i++)
         {
             AttachmentsList.Items.Add(mail.Attachments[i + 1].FileName + $@" ({(mail.Attachments[i + 1].Size / 1024):N}kB)");
         }
     }
 }
コード例 #29
0
        public ConfirmationWindow(CheckList checkList, Outlook._MailItem mailItem)
        {
            DataContext = new ConfirmationWindowViewModel(checkList);
            _mailItem   = mailItem;

            InitializeComponent();

            //送信遅延時間を表示(設定)欄に入れる。
            DeferredDeliveryMinutesBox.Text = checkList.DeferredMinutes.ToString();
        }
コード例 #30
0
ファイル: ReportMe.cs プロジェクト: Pezmet/ReportMe
        //format the email
        private void mailto_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Outlook.Application oApp      = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook._MailItem   oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
            DateTime dt = DateTime.Now;

            oMailItem.To      = "*****@*****.**";
            oMailItem.CC      = "*****@*****.**";
            oMailItem.Subject = "[Report Me] " + String.Format("{0:d-mm-yyy}", dt);
            oMailItem.Display(false);
        }
コード例 #31
0
    public MagnetMailItemForm( Engine engine, Outlook._MailItem mailItem, Categories categories )
    {
      // 
      InitializeComponent();

      // the engine to create new categories.
      _engine = engine;

      // the categories
      _categories = categories;

      // the mail item
      _mailItem = mailItem;
    }
コード例 #32
0
 public void Move(IMailFolder newFolder)
 {
     var provider = newFolder as MailFolderProviderOM;
     _mailItem = _mailItem.Move(provider.Handle);
 }
コード例 #33
0
 internal MailItemProviderOM(Outlook.MailItem mailItem)
 {
     _mailItem = mailItem;
 }
コード例 #34
0
 /// <summary>
 /// Moves Mail item into new folder
 /// </summary>
 /// <param name="newFolder" - Folder object representing Folder to move to></param>
 public void Move(MailFolder newFolder)
 {
     _mailitem = _mailitem.Move(newFolder.OutlookFolderItem);
 }
コード例 #35
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="mailItem"></param>
 public MailItem(Outlook.MailItem mailItem)
 {
     _mailitem = mailItem;
 }
コード例 #36
-1
ファイル: OutlookPortal.cs プロジェクト: mind0n/hive
		public OutlookPortal()
		{
			oApp = new Microsoft.Office.Interop.Outlook.Application();
			oNameSpace = oApp.GetNamespace("MAPI");
			oOutboxFolder = oNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderOutbox);
			oNameSpace.Logon(null, null, false, false);
			oMailItem =	(Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
			
		}