Exemple #1
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);
            }
        }
Exemple #2
0
        public void SendMail(string Subject, string ToAddress, string CCAddress, string Body, List <string> Attachments, bool RequestReadReceipt, bool HighPriority)
        {
            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;

            if (HighPriority)
            {
                oMailItem.Importance = Outlook.OlImportance.olImportanceHigh;
            }

            if (Attachments.Count > 0)
            {
                string thisAttachment;

                for (int i = 0; i <= Attachments.Count - 1; i++)
                {
                    thisAttachment = Convert.ToString(Attachments[i]);
                    if (thisAttachment != string.Empty)
                    {
                        oMailItem.Attachments.Add(thisAttachment);
                    }
                }
            }

            if (oMailItem.Recipients.ResolveAll())
            {
                if (Mode == "LIVE")
                {
                    oMailItem.Send();
                }
                else
                {
                    oMailItem.Save();
                }
            }
            else
            {
                throw new ApplicationException("Problem with recipient " + ToAddress);
            }
        }
        private static string GetUniqueIdentifierString(Outlook._MailItem mailItem)
        {
            // does it already exist?
            if (mailItem.UserProperties[IdentifierKey] == null)
            {
                // no, it does not we need to add it.
                mailItem.UserProperties.Add(IdentifierKey, Outlook.OlUserPropertyType.olText, false, Outlook.OlFormatText.olFormatTextText);

                // set the current entry id, the number itself is immaterial.
                mailItem.UserProperties[IdentifierKey].Value = mailItem.EntryID;
                mailItem.Save();
            }

            // we can now return the value as we know it.
            return(mailItem.UserProperties[IdentifierKey].Value);
        }