Beispiel #1
0
		private static void SendEmail(IAppError appError)
		{
			//If email reporting has been turned on, send detailed error report.
			Core coreConfig = ConfigManager.GetGalleryServerProConfigSection().Core;

			if (!coreConfig.SendEmailOnError)
				return;

			MailAddress emailRecipient = new MailAddress(coreConfig.EmailToAddress, coreConfig.EmailToName);
			MailAddress emailSender = new MailAddress(coreConfig.EmailFromAddress, coreConfig.EmailFromName);
			try
			{
				using (MailMessage mail = new MailMessage(emailSender, emailRecipient))
				{
					if (String.IsNullOrEmpty(appError.ExceptionType)) 
						mail.Subject = Resources.Email_Subject_When_No_Ex_Type_Present;
					else
						mail.Subject = String.Concat(Resources.Email_Subject_Prefix_When_Ex_Type_Present, " ", appError.ExceptionType);

					mail.Body = appError.ToHtmlPage();
					mail.IsBodyHtml = true;

					SmtpClient smtpClient = new SmtpClient();
					smtpClient.EnableSsl = coreConfig.SendEmailUsingSsl;

					// Specify SMTP server if it's in galleryserverpro.config. The server might have been assigned via web.config,
					// so only update this if we have a config setting.
					if (!String.IsNullOrEmpty(coreConfig.SmtpServer))
					{
						smtpClient.Host = coreConfig.SmtpServer;
					}

					// Specify port number if it's in galleryserverpro.config and it's not the default value of 25. The port 
					// might have been assigned via web.config, so only update this if we have a config setting.
					int smtpServerPort;
					if (!Int32.TryParse(coreConfig.SmtpServerPort, out smtpServerPort))
						smtpServerPort = int.MinValue;

					if ((smtpServerPort > 0) && (smtpServerPort != 25))
					{
						smtpClient.Port = smtpServerPort;
					}

					smtpClient.Send(mail);
				}
			}
			catch (Exception ex2)
			{
				string errorMsg = String.Concat(ex2.GetType(), ": ", ex2.Message);

				if (ex2.InnerException != null)
					errorMsg += String.Concat(" ", ex2.InnerException.GetType(), ": ", ex2.InnerException.Message);

				appError.ExceptionData.Add(new KeyValuePair<string, string>(Resources.Cannot_Send_Email_Lbl, errorMsg));
			}
		}
Beispiel #2
0
        /// <summary>
        /// Sends an e-mail containing details about the <paramref name="appError" /> to the specified <paramref name="user" />. Returns
        /// <c>true</c> if the e-mail is successfully sent.
        /// </summary>
        /// <param name="appError">The application error to be sent to users.</param>
        /// <param name="user">The user to send the e-mail to.</param>
        /// <param name="gallerySettings">The gallery settings containing the e-mail configuration data.</param>
        /// <param name="emailSender">The account that that will appear in the "From" portion of the e-mail.</param>
        /// <returns>Returns <c>true</c> if the e-mail is successfully sent; otherwise <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="appError" />, <paramref name="user" />,
        /// <paramref name="gallerySettings" />, or <paramref name="emailSender" /> is null.</exception>
        private static bool SendMail(IAppError appError, IUserAccount user, IGallerySettings gallerySettings, MailAddress emailSender)
        {
            #region Validation

            if (appError == null)
            {
                throw new ArgumentNullException("appError");
            }

            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            if (gallerySettings == null)
            {
                throw new ArgumentNullException("gallerySettings");
            }

            if (emailSender == null)
            {
                throw new ArgumentNullException("emailSender");
            }

            #endregion

            bool emailWasSent = false;

            if (!IsValidEmail(user.Email))
            {
                return(false);
            }

            MailAddress emailRecipient = new MailAddress(user.Email, user.UserName);
            try
            {
                using (MailMessage mail = new MailMessage(emailSender, emailRecipient))
                {
                    if (String.IsNullOrEmpty(appError.ExceptionType))
                    {
                        mail.Subject = Resources.Email_Subject_When_No_Ex_Type_Present;
                    }
                    else
                    {
                        mail.Subject = String.Concat(Resources.Email_Subject_Prefix_When_Ex_Type_Present, " ", appError.ExceptionType);
                    }

                    mail.Body       = appError.ToHtmlPage();
                    mail.IsBodyHtml = true;

                    using (SmtpClient smtpClient = new SmtpClient())
                    {
                        smtpClient.EnableSsl = gallerySettings.SendEmailUsingSsl;

                        // Specify SMTP server if it is specified. The server might have been assigned via web.config,
                        // so only update this if we have a config setting.
                        if (!String.IsNullOrEmpty(gallerySettings.SmtpServer))
                        {
                            smtpClient.Host = gallerySettings.SmtpServer;
                        }

                        // Specify port number if it is specified and it's not the default value of 25. The port
                        // might have been assigned via web.config, so only update this if we have a config setting.
                        int smtpServerPort;
                        if (!Int32.TryParse(gallerySettings.SmtpServerPort, out smtpServerPort))
                        {
                            smtpServerPort = int.MinValue;
                        }

                        if ((smtpServerPort > 0) && (smtpServerPort != 25))
                        {
                            smtpClient.Port = smtpServerPort;
                        }

                        smtpClient.Send(mail);
                    }

                    emailWasSent = true;
                }
            }
            catch (Exception ex2)
            {
                string errorMsg = String.Concat(ex2.GetType(), ": ", ex2.Message);

                if (ex2.InnerException != null)
                {
                    errorMsg += String.Concat(" ", ex2.InnerException.GetType(), ": ", ex2.InnerException.Message);
                }

                appError.ExceptionData.Add(new KeyValuePair <string, string>(Resources.Cannot_Send_Email_Lbl, errorMsg));
            }

            return(emailWasSent);
        }
Beispiel #3
0
        /// <summary>
        /// Sends an e-mail containing details about the <paramref name="appError" /> to the specified <paramref name="user" />. Returns
        /// <c>true</c> if the e-mail is successfully sent.
        /// </summary>
        /// <param name="appError">The application error to be sent to users.</param>
        /// <param name="user">The user to send the e-mail to.</param>
        /// <param name="gallerySettings">The gallery settings containing the e-mail configuration data.</param>
        /// <param name="emailSender">The account that that will appear in the "From" portion of the e-mail.</param>
        /// <returns>Returns <c>true</c> if the e-mail is successfully sent; otherwise <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">Thrown when <paramref name="appError" />, <paramref name="user" />, 
        /// <paramref name="gallerySettings" />, or <paramref name="emailSender" /> is null.</exception>
        private static bool SendMail(IAppError appError, IUserAccount user, IGallerySettings gallerySettings, MailAddress emailSender)
        {
            #region Validation

            if (appError == null)
                throw new ArgumentNullException("appError");

            if (user == null)
                throw new ArgumentNullException("user");

            if (gallerySettings == null)
                throw new ArgumentNullException("gallerySettings");

            if (emailSender == null)
                throw new ArgumentNullException("emailSender");

            #endregion

            bool emailWasSent = false;

            if (!IsValidEmail(user.Email))
            {
                return false;
            }

            MailAddress emailRecipient = new MailAddress(user.Email, user.UserName);
            try
            {
                using (MailMessage mail = new MailMessage(emailSender, emailRecipient))
                {
                    if (String.IsNullOrEmpty(appError.ExceptionType))
                        mail.Subject = Resources.Email_Subject_When_No_Ex_Type_Present;
                    else
                        mail.Subject = String.Concat(Resources.Email_Subject_Prefix_When_Ex_Type_Present, " ", appError.ExceptionType);

                    mail.Body = appError.ToHtmlPage();
                    mail.IsBodyHtml = true;

                    using (SmtpClient smtpClient = new SmtpClient())
                    {
                        smtpClient.EnableSsl = gallerySettings.SendEmailUsingSsl;

                        // Specify SMTP server if it is specified. The server might have been assigned via web.config,
                        // so only update this if we have a config setting.
                        if (!String.IsNullOrEmpty(gallerySettings.SmtpServer))
                        {
                            smtpClient.Host = gallerySettings.SmtpServer;
                        }

                        // Specify port number if it is specified and it's not the default value of 25. The port
                        // might have been assigned via web.config, so only update this if we have a config setting.
                        int smtpServerPort;
                        if (!Int32.TryParse(gallerySettings.SmtpServerPort, out smtpServerPort))
                            smtpServerPort = int.MinValue;

                        if ((smtpServerPort > 0) && (smtpServerPort != 25))
                        {
                            smtpClient.Port = smtpServerPort;
                        }

                        smtpClient.Send(mail);
                    }

                    emailWasSent = true;
                }
            }
            catch (Exception ex2)
            {
                string errorMsg = String.Concat(ex2.GetType(), ": ", ex2.Message);

                if (ex2.InnerException != null)
                    errorMsg += String.Concat(" ", ex2.InnerException.GetType(), ": ", ex2.InnerException.Message);

                appError.ExceptionData.Add(new KeyValuePair<string, string>(Resources.Cannot_Send_Email_Lbl, errorMsg));
            }

            return emailWasSent;
        }
Beispiel #4
0
        private static void SendEmail(IAppError appError)
        {
            //If email reporting has been turned on, send detailed error report.
            Core coreConfig = ConfigManager.GetGalleryServerProConfigSection().Core;

            if (!coreConfig.SendEmailOnError)
            {
                return;
            }

            MailAddress emailRecipient = new MailAddress(coreConfig.EmailToAddress, coreConfig.EmailToName);
            MailAddress emailSender    = new MailAddress(coreConfig.EmailFromAddress, coreConfig.EmailFromName);

            try
            {
                using (MailMessage mail = new MailMessage(emailSender, emailRecipient))
                {
                    if (String.IsNullOrEmpty(appError.ExceptionType))
                    {
                        mail.Subject = Resources.Email_Subject_When_No_Ex_Type_Present;
                    }
                    else
                    {
                        mail.Subject = String.Concat(Resources.Email_Subject_Prefix_When_Ex_Type_Present, " ", appError.ExceptionType);
                    }

                    mail.Body       = appError.ToHtmlPage();
                    mail.IsBodyHtml = true;

                    SmtpClient smtpClient = new SmtpClient();
                    smtpClient.EnableSsl = coreConfig.SendEmailUsingSsl;

                    // Specify SMTP server if it's in galleryserverpro.config. The server might have been assigned via web.config,
                    // so only update this if we have a config setting.
                    if (!String.IsNullOrEmpty(coreConfig.SmtpServer))
                    {
                        smtpClient.Host = coreConfig.SmtpServer;
                    }

                    // Specify port number if it's in galleryserverpro.config and it's not the default value of 25. The port
                    // might have been assigned via web.config, so only update this if we have a config setting.
                    int smtpServerPort;
                    if (!Int32.TryParse(coreConfig.SmtpServerPort, out smtpServerPort))
                    {
                        smtpServerPort = int.MinValue;
                    }

                    if ((smtpServerPort > 0) && (smtpServerPort != 25))
                    {
                        smtpClient.Port = smtpServerPort;
                    }

                    smtpClient.Send(mail);
                }
            }
            catch (Exception ex2)
            {
                string errorMsg = String.Concat(ex2.GetType(), ": ", ex2.Message);

                if (ex2.InnerException != null)
                {
                    errorMsg += String.Concat(" ", ex2.InnerException.GetType(), ": ", ex2.InnerException.Message);
                }

                appError.ExceptionData.Add(new KeyValuePair <string, string>(Resources.Cannot_Send_Email_Lbl, errorMsg));
            }
        }