コード例 #1
0
ファイル: MailUtil.cs プロジェクト: jkdufair/cfUtils
        /// <summary>
        /// Openes a prepared mail-sending-window using the installed Outlook.
        /// </summary>
        /// <param name="senderAddress">The sender.</param>
        /// <param name="receipients">The receipients.</param>
        /// <param name="replyToAddress">Give in an SMTP mail if you want to reply to another mail.</param>
        /// <param name="subject">The subject of the mail.</param>
        /// <param name="body">The body-text.</param>
        /// <param name="bcc">One or many BCC receipients seprated by ";".</param>
        /// <param name="attachements">A list of strings representing file-URIs to attach.</param>
        /// <param name="format">The format of the body.</param>
        /// <returns><c>true</c>, if the process succeeded.</returns>
        public static bool OpenOutlookMail(
            string senderAddress,
            IEnumerable <string> receipients,
            string replyToAddress,
            string subject,
            string body,
            string bcc = "",
            IEnumerable <string> attachements = null,
            OutlookMailBodyFormat format      = OutlookMailBodyFormat.Plain)
        {
            var result          = false;
            var outlookMailItem = GetMailItem(senderAddress, receipients, replyToAddress, subject, body, bcc, attachements, format);

            outlookMailItem.Save();
            try
            {
                outlookMailItem.Display(false);
                result = true;
            }
            catch (Exception ex)
            {
                TraceUtil.WriteTraceError(ex.Message);
            }
            return(result);
        }
コード例 #2
0
ファイル: MailUtil.cs プロジェクト: jkdufair/cfUtils
 /// <summary>
 /// Openes a prepared mail-sending-window using the installed Outlook.
 /// </summary>
 /// <param name="senderAddress">The sender.</param>
 /// <param name="receipient">The receipient.</param>
 /// <param name="replyToAddress">Give in an SMTP mail if you want to reply to another mail.</param>
 /// <param name="subject">The subject of the mail.</param>
 /// <param name="body">The body-text.</param>
 /// <param name="bcc">One or many BCC receipients seprated by ";".</param>
 /// <param name="attachements">A list of strings representing file-URIs to attach.</param>
 /// <param name="format">The format of the body.</param>
 /// <returns><c>true</c>, if the process succeeded.</returns>
 public static bool OpenOutlookMail(
     string senderAddress,
     string receipient,
     string replyToAddress,
     string subject,
     string body = "",
     string bcc  = "",
     IEnumerable <string> attachements = null,
     OutlookMailBodyFormat format      = OutlookMailBodyFormat.Plain)
 {
     return(OpenOutlookMail(senderAddress, new[] { receipient }, replyToAddress, subject, body, bcc, attachements, format));
 }
コード例 #3
0
ファイル: MailUtil.cs プロジェクト: codingfreak/cfUtils
 /// <summary>
 /// Openes a prepared mail-sending-window using the installed Outlook.
 /// </summary>
 /// <param name="senderAddress">The sender.</param>
 /// <param name="receipient">The receipient.</param>
 /// <param name="replyToAddress">Give in an SMTP mail if you want to reply to another mail.</param>
 /// <param name="subject">The subject of the mail.</param>
 /// <param name="body">The body-text.</param>
 /// <param name="bcc">One or many BCC receipients seprated by ";".</param>
 /// <param name="attachements">A list of strings representing file-URIs to attach.</param>
 /// <param name="format">The format of the body.</param>
 /// <returns><c>true</c>, if the process succeeded.</returns>
 public static bool OpenOutlookMail(
     string senderAddress,
     string receipient,
     string replyToAddress,
     string subject,
     string body = "",
     string bcc = "",
     IEnumerable<string> attachements = null,
     OutlookMailBodyFormat format = OutlookMailBodyFormat.Plain)
 {
     return OpenOutlookMail(senderAddress, new[] { receipient }, replyToAddress, subject, body, bcc, attachements, format);
 }
コード例 #4
0
ファイル: MailUtil.cs プロジェクト: jkdufair/cfUtils
        /// <summary>
        /// Generates an OutlookMailItem using dynamic types independently from the locally installed Office-Version.
        /// </summary>
        /// <param name="senderAddress">The sender.</param>
        /// <param name="receipients">The receipients.</param>
        /// <param name="replyToAddress">Give in an SMTP mail if you want to reply to another mail.</param>
        /// <param name="subject">The subject of the mail.</param>
        /// <param name="body">The body-text.</param>
        /// <param name="bcc">One or many BCC receipients seprated by ";".</param>
        /// <param name="attachements">A list of strings representing file-URIs to attach.</param>
        /// <param name="format">The format of the body.</param>
        /// <returns>The ready-to-use mail item.</returns>
        private static dynamic GetMailItem(
            string senderAddress,
            IEnumerable <string> receipients,
            string replyToAddress,
            string subject,
            string body,
            string bcc = "",
            IEnumerable <string> attachements = null,
            OutlookMailBodyFormat format      = OutlookMailBodyFormat.Plain)
        {
            var outlookApplicationType = Type.GetTypeFromProgID("Outlook.Application");

            if (outlookApplicationType == null)
            {
                throw new InvalidOperationException("Outlook not installed on this machine.");
            }
            dynamic outlookApplication = Activator.CreateInstance(outlookApplicationType);
            dynamic outlookMailItem    = outlookApplication.CreateItem(0);

            outlookMailItem.Subject    = subject;
            outlookMailItem.Body       = body;
            outlookMailItem.To         = receipients.ToArray();
            outlookMailItem.Subject    = subject;
            outlookMailItem.BodyFormat = (int)format;
            outlookMailItem.BCC        = bcc;
            if (!string.IsNullOrEmpty(replyToAddress))
            {
                // we have to add a reply-address
                outlookMailItem.ReplyRecipients.Add(replyToAddress);
            }
            if (attachements != null && attachements.Any())
            {
                // add the attachements
                foreach (var strAtt in attachements.Where(strAtt => !string.IsNullOrEmpty(strAtt) && File.Exists(strAtt)))
                {
                    outlookMailItem.Attachments.Add(strAtt, 5, 1, string.Empty);
                }
            }
            return(outlookMailItem);
        }
コード例 #5
0
ファイル: MailUtil.cs プロジェクト: codingfreak/cfUtils
 /// <summary>
 /// Openes a prepared mail-sending-window using the installed Outlook.
 /// </summary>
 /// <param name="senderAddress">The sender.</param>
 /// <param name="receipients">The receipients.</param>
 /// <param name="replyToAddress">Give in an SMTP mail if you want to reply to another mail.</param>
 /// <param name="subject">The subject of the mail.</param>
 /// <param name="body">The body-text.</param>
 /// <param name="bcc">One or many BCC receipients seprated by ";".</param>
 /// <param name="attachements">A list of strings representing file-URIs to attach.</param>
 /// <param name="format">The format of the body.</param>
 /// <returns><c>true</c>, if the process succeeded.</returns>
 public static bool OpenOutlookMail(
     string senderAddress,
     IEnumerable<string> receipients,
     string replyToAddress,
     string subject,
     string body,
     string bcc = "",
     IEnumerable<string> attachements = null,
     OutlookMailBodyFormat format = OutlookMailBodyFormat.Plain)
 {
     var result = false;
     var outlookMailItem = GetMailItem(senderAddress, receipients, replyToAddress, subject, body, bcc, attachements, format);
     outlookMailItem.Save();
     try
     {
         outlookMailItem.Display(false);
         result = true;
     }
     catch (Exception ex)
     {
         TraceUtil.WriteTraceError(ex.Message);
     }
     return result;
 }
コード例 #6
0
ファイル: MailUtil.cs プロジェクト: codingfreak/cfUtils
 /// <summary>
 /// Generates an OutlookMailItem using dynamic types independently from the locally installed Office-Version.
 /// </summary>
 /// <param name="senderAddress">The sender.</param>
 /// <param name="receipients">The receipients.</param>
 /// <param name="replyToAddress">Give in an SMTP mail if you want to reply to another mail.</param>
 /// <param name="subject">The subject of the mail.</param>
 /// <param name="body">The body-text.</param>
 /// <param name="bcc">One or many BCC receipients seprated by ";".</param>
 /// <param name="attachements">A list of strings representing file-URIs to attach.</param>
 /// <param name="format">The format of the body.</param>
 /// <returns>The ready-to-use mail item.</returns>
 private static dynamic GetMailItem(
     string senderAddress,
     IEnumerable<string> receipients,
     string replyToAddress,
     string subject,
     string body,
     string bcc = "",
     IEnumerable<string> attachements = null,
     OutlookMailBodyFormat format = OutlookMailBodyFormat.Plain)
 {
     var outlookApplicationType = Type.GetTypeFromProgID("Outlook.Application");
     if (outlookApplicationType == null)
     {
         throw new InvalidOperationException("Outlook not installed on this machine.");
     }
     dynamic outlookApplication = Activator.CreateInstance(outlookApplicationType);
     dynamic outlookMailItem = outlookApplication.CreateItem(0);
     outlookMailItem.Subject = subject;
     outlookMailItem.Body = body;
     outlookMailItem.To = receipients.ToArray();
     outlookMailItem.Subject = subject;
     outlookMailItem.BodyFormat = (int)format;
     outlookMailItem.BCC = bcc;
     if (!string.IsNullOrEmpty(replyToAddress))
     {
         // we have to add a reply-address
         outlookMailItem.ReplyRecipients.Add(replyToAddress);
     }
     if (attachements != null && attachements.Any())
     {
         // add the attachements
         foreach (var strAtt in attachements.Where(strAtt => !string.IsNullOrEmpty(strAtt) && File.Exists(strAtt)))
         {
             outlookMailItem.Attachments.Add(strAtt, 5, 1, string.Empty);
         }
     }
     return outlookMailItem;
 }