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; } } }
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; } } }