/// <summary>
        ///   Send this email
        /// </summary>
        public void Send(bool verbose = true)
        {
            Cursor.Current = Cursors.WaitCursor;

            try
            {
                var email = new Email();
                if (!string.IsNullOrEmpty(Report))
                {
                    var mht    = new Mht();
                    var emlStr = mht.GetEML(Report);
                    if (mht.LastMethodSuccess != true)
                    {
                        throw new Exception(mht.LastErrorText);
                    }

                    var success = email.SetFromMimeText(emlStr);
                    if (!success)
                    {
                        throw new Exception(email.LastErrorText);
                    }
                }

                email.AddTo("Damage Report", @"*****@*****.**");
                email.From    = @"*****@*****.**";
                email.Subject = Subject;

                if (!string.IsNullOrEmpty(CC))
                {
                    email.AddCC(CC, CC);
                }

                SendMail(email);
                Cursor.Current = Cursors.Default;

                if (verbose)
                {
                    MessageBox.Show("Email Send Successful", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception e)
            {
                Cursor.Current = Cursors.Default;
                var reason = string.Format(@"Failed to send email : {0}", e.Message);
                MessageBox.Show(reason, @"Error", MessageBoxButtons.OK);
            }
        }
Exemple #2
0
        /// <summary>
        /// cover file word to body hmtl of mail,which embed fictures
        /// </summary>
        /// <param name="PathWordTemplate">path to word template file</param>
        /// <param name="Mail">Mail is embed body</param>
        /// <returns></returns>
        private static bool HTMLBody(DataSet DataFill, string PathWordTemplate, ref Email Mail)
        {
            string path = FrameworkParams.TEMP_FOLDER + @"\WordTemp";
            if (!System.IO.Directory.Exists(path))
                System.IO.Directory.CreateDirectory(path);
            path += PathWordTemplate.Substring(PathWordTemplate.LastIndexOf("\\"));
            WordDocument WordDoc = new WordDocument();
            try
            {
                WordDoc.Open(PathWordTemplate);
                for (int i = 0; i < DataFill.Tables.Count; i++)
                {
                    WordDoc.MailMerge.ExecuteGroup(DataFill.Tables[i]);
                }
                WordDoc.Save(path);

                Word.ApplicationClass wd = new Word.ApplicationClass();
                Word.Document document = new Word.Document();
                object fileName = (object)path;
                object newTemplate = false;
                object docType = 0;
                object isVisible = true;
                object missing = System.Reflection.Missing.Value;

                document = wd.Documents.Add(ref fileName, ref newTemplate, ref docType, ref isVisible);

                object oFileName = (object)(path.Substring(0, path.LastIndexOf(".")) + ".html");
                object oSaveFormat = (object)(Word.WdSaveFormat.wdFormatHTML);

                if (System.IO.File.Exists(oFileName.ToString()))
                    System.IO.File.Delete(oFileName.ToString());

                document.SaveAs(ref oFileName,
                                ref oSaveFormat,
                                ref missing,
                                ref missing,
                                ref missing,
                                ref missing,
                                ref missing,
                                ref missing,
                                ref missing,
                                ref missing,
                                ref missing);
                document.Close(ref missing, ref missing, ref missing);
                wd.Quit(ref missing, ref missing, ref missing);

                Mht mailbody = new Mht();
                mailbody.UnlockComponent("MHT-TEAMBEAN_1E1F4760821H");
                mailbody.UseCids = true;
                Mail = mailbody.GetEmail(oFileName.ToString());

                return true;
            }
            catch
            {
                return false;
            }
        }