這就是我所做的。這並不完美,但它有幫助。
protected void CreateUserWizard1_SendMailError(object sender, SendMailErrorEventArgs e)
{
// e.Exception can be one of the exceptions generated from SmtpClient.Send(MailMessage)
if (e.Exception is SmtpFailedRecipientException)
{
// The message could not be delivered to one or more of the recipients in To, CC, or BCC()()().
// TODO: Set an error message on the page
e.Handled = true;
// Since the user has already been created at this point, we need to remove them.
Membership.DeleteUser(CreateUserWizard1.UserName);
// Set an internal flag for use in the ActiveStepChanged event.
emailFailed = true;
return;
}
}
protected void CreateUserWizard1_ActiveStepChanged(object sender, EventArgs e)
{
if (CreateUserWizard1.ActiveStep != CreateUserWizard1.CompleteStep)
return;
if (emailFailed)
{
// If the email failed, keep the user on the first step.
CreateUserWizard1.ActiveStepIndex = 0;
return;
}
}
確實夠了,但是如何讓用戶知道電子郵件無法發送? –
查看一些API,例如GMAIL,或者查看Exchange是否具有該功能,因爲沒有事件在電子郵件失敗時觸發,傳遞失敗將被髮回給您,並且您必須處理那個消息來解決這個問題。這可能是幾天/幾周後,這就是問題所在。 –