コード例 #1
0
ファイル: Emailer.cs プロジェクト: Mwelase-dev/My-SPA-APP-2
        /// <summary>
        /// Sends an email to the addresses supplied in the TO, CC and BCC lists
        /// </summary>
        /// <returns>true if the message was sent successfully</returns>
        public bool SendEmail()
        {
            // Setup Email Client here
            if ((TOList.Count > 0) || (CCList.Count > 0) || (BCList.Count > 0))
            {
                message.Subject = this.subject;
                message.Body    = this.body;
                message.From    = new MailAddress("*****@*****.**");

                // Add addresses
                TOList.ForEach(x => message.To.Add(x));
                CCList.ForEach(x => message.CC.Add(x));
                BCList.ForEach(x => message.Bcc.Add(x));

                // Try sending the actual mail....
                try
                {
                    /*
                     *
                     #region Debug info
                     * WriteAddressToDebug();
                     #endregion
                     #if DEBUG
                     *  Trace.WriteLine("Debug on. Not sending emails");
                     #else
                     *  Trace.WriteLine("Debug off. SENDING EMAILS!!!!!");
                     *  smtp.Send(message);
                     #endif         */

                    Trace.WriteLine("Debug off. SENDING EMAILS!!!!!");
                    message.IsBodyHtml = true;


                    if (Convert.ToBoolean(WebConfigurationManager.AppSettings["RolledOut"]))
                    {
                        smtp.Send(message);
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex.ToString());
                    throw;
                    //TODO: Need to check if the sending fails here. HAd a case where the email address doesn't exist, but C# throws an exception an exception on that case. We need to log it and re-throwing is not required.
                }
            }
            return(false);
        }
コード例 #2
0
ファイル: Emailer.cs プロジェクト: Mwelase-dev/My-SPA-APP-2
        private void WriteAddressToDebug()
        {
            Trace.WriteLine("Sending email(s) to:");

            Trace.WriteLine("TO:");
            Trace.WriteLine(String.Format("  -- has {0} addresses", TOList.Count.ToString()));
            TOList.ForEach(x => Trace.WriteLine(string.Format("    -- {0} ", x.ToString())));

            Trace.WriteLine("CC:");
            Trace.WriteLine(String.Format("  -- has {0} addresses", CCList.Count.ToString()));
            CCList.ForEach(x => Trace.WriteLine(string.Format("    -- {0}", x.ToString())));

            Trace.WriteLine("Bcc:");
            Trace.WriteLine(String.Format("  -- has {0} addresses", BCList.Count.ToString()));
            BCList.ForEach(x => Trace.WriteLine(string.Format("    -- {0}", x.ToString())));

            Trace.WriteLine("... ... ...");
            Trace.WriteLine(message.ToString());
            Trace.WriteLine("... ... ...");
        }