Exemplo n.º 1
0
        internal static void SendPasswordMail(string email, string userName, string password,
                                              MailDefinition mailDefinition,
                                              string defaultSubject, string defaultBody,
                                              OnSendingMailDelegate onSendingMailDelegate,
                                              OnSendMailErrorDelegate onSendMailErrorDelegate,
                                              Control owner)
        {
            // If the MailAddress ctor throws an exception, raise the error event but do not
            // rethrow the exception.  We do not rethrow the exception since the email address
            // is user-entered data, and it should not cause an unhandled exception in the page.
            // If any other part of creating or sending the MailMessage throws an exception,
            // it is most likely a developer error so the exception should be rethrown.
            // (VSWhidbey 490984)
            try {
                new MailAddress(email);
            }
            catch (Exception e) {
                SendMailErrorEventArgs args = new SendMailErrorEventArgs(e);
                // SendMailErrorEventArgs.Handled should be true, to indicate that the exception
                // will not be rethrown. (VSWhidbey 529233)
                args.Handled = true;
                onSendMailErrorDelegate(args);
                return;
            }

            try {
                using (MailMessage message = CreateMailMessage(email, userName, password,
                                                               mailDefinition, defaultBody,
                                                               owner)) {
                    if (mailDefinition.SubjectInternal == null && defaultSubject != null)
                    {
                        message.Subject = defaultSubject;
                    }
                    MailMessageEventArgs args = new MailMessageEventArgs(message);
                    onSendingMailDelegate(args);
                    if (args.Cancel)
                    {
                        return;
                    }

                    SmtpClient smtp = new SmtpClient();
                    smtp.Send(message);
                }
            } catch (Exception e) {
                SendMailErrorEventArgs args = new SendMailErrorEventArgs(e);
                onSendMailErrorDelegate(args);

                // If the error wasn't handled, we rethrow
                if (!args.Handled)
                {
                    throw;
                }
            }
        }
Exemplo n.º 2
0
 internal static void SendPasswordMail(string email, string userName, string password, MailDefinition mailDefinition, string defaultSubject, string defaultBody, OnSendingMailDelegate onSendingMailDelegate, OnSendMailErrorDelegate onSendMailErrorDelegate, Control owner)
 {
     try
     {
         new MailAddress(email);
     }
     catch (Exception exception)
     {
         SendMailErrorEventArgs e = new SendMailErrorEventArgs(exception)
         {
             Handled = true
         };
         onSendMailErrorDelegate(e);
         return;
     }
     try
     {
         using (MailMessage message = CreateMailMessage(email, userName, password, mailDefinition, defaultBody, owner))
         {
             if ((mailDefinition.SubjectInternal == null) && (defaultSubject != null))
             {
                 message.Subject = defaultSubject;
             }
             MailMessageEventArgs args2 = new MailMessageEventArgs(message);
             onSendingMailDelegate(args2);
             if (!args2.Cancel)
             {
                 new SmtpClient().Send(message);
             }
         }
     }
     catch (Exception exception2)
     {
         SendMailErrorEventArgs args3 = new SendMailErrorEventArgs(exception2);
         onSendMailErrorDelegate(args3);
         if (!args3.Handled)
         {
             throw;
         }
     }
 }
Exemplo n.º 3
0
		public static void w_SendMailError (object sender, SendMailErrorEventArgs e)
		{
			e.Handled = true;
		}
 protected void PasswordRecovery1_SendMailError(object sender, SendMailErrorEventArgs e)
 {
     log.Info(string.Format("{0}: {1}", Framework.LoggingOptions.PasswordRecovery_SendMailError.ToString(), this.PasswordRecovery1.UserName));
 }
 protected virtual void OnSendMailError(SendMailErrorEventArgs e)
 {
     SendMailErrorEventHandler handler = (SendMailErrorEventHandler) base.Events[EventSendMailError];
     if (handler != null)
     {
         handler(this, e);
     }
 }
 protected virtual new void OnSendMailError(SendMailErrorEventArgs e)
 {
 }
		void SendMail (string username, string password)
		{
			MembershipUser user = MembershipProviderInternal.GetUser (UserName, false);
			if (user == null)
				return;

			ListDictionary dictionary = new ListDictionary ();
			dictionary.Add ("<%USERNAME%>", username);
			dictionary.Add ("<%PASSWORD%>", password);

			MailMessage message = MailDefinition.CreateMailMessage (user.Email, dictionary, this);

			MailMessageEventArgs args = new MailMessageEventArgs (message);
			OnSendingMail (args);

			SmtpClient smtpClient = new SmtpClient ();
			try {
				smtpClient.Send (message);
			}
			catch (Exception e) {
				SendMailErrorEventArgs mailArgs = new SendMailErrorEventArgs (e);
				OnSendMailError (mailArgs);
				if (!mailArgs.Handled)
					throw e;
			}
		}
 /// <summary>
 /// Called if the mailsettings don't exist in the web.config.  This is ok, since we use SharePoint
 /// to send the email. Simply call our send email function.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void _ctlPasswordRecovery_SendMailError(object sender, SendMailErrorEventArgs e)
 {
     e.Handled = true;
     SendEmail();
 }
Exemplo n.º 9
0
		void SendPasswordByMail (string username, string password)
		{
			MembershipUser user = MembershipProviderInternal.GetUser (UserName, false);
			if (user == null)
				return;

			// DO NOT change format of the message - it has to be exactly the same as in
			// .NET as some software (e.g. YetAnotherForum) depends on it.
			string messageText = "Please return to the site and log in using the following information.\n" +
				"User Name: <%USERNAME%>\nPassword: <%PASSWORD%>\n";

			ListDictionary dictionary = new ListDictionary (StringComparer.OrdinalIgnoreCase);
			dictionary.Add ("<%USERNAME%>", username);
			dictionary.Add ("<% UserName %>", username);
			dictionary.Add ("<%PASSWORD%>", password);
			dictionary.Add ("<% Password %>", password);

			MailMessage message = null;
			
			if (MailDefinition.BodyFileName.Length == 0)
				message = MailDefinition.CreateMailMessage (user.Email, dictionary, messageText, this);
			else
				message = MailDefinition.CreateMailMessage (user.Email, dictionary, this);

			if (string.IsNullOrEmpty (message.Subject))
				message.Subject = "Password";

			MailMessageEventArgs args = new MailMessageEventArgs (message);
			OnSendingMail (args);

			SmtpClient smtpClient = new SmtpClient ();
			try {
				smtpClient.Send (message);
			}
			catch (Exception e) {
				SendMailErrorEventArgs mailArgs = new SendMailErrorEventArgs (e);
				OnSendMailError (mailArgs);
				if (!mailArgs.Handled)
					throw e;
			}
		}
 protected virtual new void OnSendMailError(SendMailErrorEventArgs e)
 {
 }
 protected void OnSendMailError(object sender, SendMailErrorEventArgs e)
 {
     if (!e.Handled)
     {
         _state = State.SendMailError;
         _currentErrorText = e.Exception.Message;
     }
 }
Exemplo n.º 12
0
		protected void PasswordRecovery1_SendMailError( object sender, SendMailErrorEventArgs e )
		{
			// it will fail to send the message...
			e.Handled = true;
		}
 protected void CreateUserWizard1_SendMailError(object sender, SendMailErrorEventArgs e)
 {
     Server.Transfer("../Error.aspx"); // Change to error page
 }
Exemplo n.º 14
0
        void PasswordRecovery1_SendMailError(object sender, SendMailErrorEventArgs e)
        {
            String logMessage = "unable to send password recovery email. Please check the system.net MailSettings section in web.config";

            log.Error(logMessage, e.Exception);
            lblMailError.Text = Resource.PasswordRecoveryMailFailureMessage;
            e.Handled = true;
            SiteLabel successLabel
                = (SiteLabel)PasswordRecovery1.SuccessTemplateContainer.FindControl("successLabel");
            if (successLabel != null) successLabel.Visible = false;
        }
		protected virtual void OnSendMailError (SendMailErrorEventArgs e)
		{
			if (Events != null) {
				SendMailErrorEventHandler eh = (SendMailErrorEventHandler) Events [SendMailErrorEvent];
				if (eh != null) eh (this, e);
			}
		}
		void SendPasswordByMail (MembershipUser user, string password)
		{
			if (user == null)
				return;
			
			if (_mailDefinition == null)
				return;
			
			string messageText = "A new account has been created for you. Please go to the site and log in using the following information.\nUser Name: <%USERNAME%>\nPassword: <%PASSWORD%>";

			ListDictionary dictionary = new ListDictionary ();
			dictionary.Add ("<%USERNAME%>", user.UserName);
			dictionary.Add ("<%PASSWORD%>", password);

			MailMessage message = null;
			
			if (MailDefinition.BodyFileName.Length == 0)
				message = MailDefinition.CreateMailMessage (user.Email, dictionary, messageText, this);
			else
				message = MailDefinition.CreateMailMessage (user.Email, dictionary, this);

			if (string.IsNullOrEmpty (message.Subject))
				message.Subject = "Account information";

			MailMessageEventArgs args = new MailMessageEventArgs (message);
			OnSendingMail (args);

			SmtpClient smtpClient = new SmtpClient ();
			try {
				smtpClient.Send (message);
			} catch (Exception e) {
				SendMailErrorEventArgs mailArgs = new SendMailErrorEventArgs (e);
				OnSendMailError (mailArgs);
				if (!mailArgs.Handled)
					throw e;
			}
		}
		protected virtual void OnSendMailError (SendMailErrorEventArgs e)
		{
			SendMailErrorEventHandler eh = events [sendMailErrorEvent] as SendMailErrorEventHandler;
			if (eh != null)
				eh (this, e);
		}