示例#1
0
        private bool CreateNewMessage(string subject, string body, EmailBodyFormat bodyFormat, ArrayList recipients,
                                      ArrayList attachments, bool useTemplatesInBody)
        {
            try
            {
                MailBodyFormat mailBodyFormat = MailBodyFormat.HTML;
                if (bodyFormat == EmailBodyFormat.PlainText)
                {
                    if (useTemplatesInBody && Settings.UseSignature)
                    {
                        body += "\r\n";
                        body += Settings.Signature;
                    }

                    mailBodyFormat = MailBodyFormat.PlainText;
                }
                else if (bodyFormat == EmailBodyFormat.Html)
                {
                    body = _rxHtmlComment.Replace(body, "");
                    body = "<HTML><BODY>" + body;
                    if (useTemplatesInBody && Settings.UseSignature)
                    {
                        body += "\r\n";
                        body += Settings.Signature;
                    }
                    body += "</BODY></HTML>";
                    Trace.WriteLine("HTML body for Outlook: \r\n" + body);
                }

                IEMsgStore msgStore = OutlookSession.GetDefaultMsgStore();
                if (msgStore != null)
                {
                    return(msgStore.CreateNewMessage(subject, body, mailBodyFormat, recipients,
                                                     attachments, OutlookSession.GetOutlookDefaultEncodingOut()));
                }
                else
                {
                    throw new ApplicationException("There are no default message store for outlook");
                }
            }
            catch (Exception exception)
            {
                ReportProblem(exception);
            }
            return(false);
        }