Net Smtpclient Error Handling
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more smtp exception failure sending mail about Stack Overflow the company Business Learn more about hiring developers or posting ads
C# Smtpclient
with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow smtpclient failure sending mail is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Get sent mail error up vote -2 down vote favorite Is there any c# send email example way to get sent error from the smtp to check if the mail is sent successfully? var smtpClient = new SmtpClient("SmtpServer"); smtpClient.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback); smtpClient.SendAsync(mail, userId); The errors I am looking for are: mail can't be deliver because the mail address not exists, mail box full etc... Regards, Meir. c# smtpclient share|improve this question edited Nov 23 '11 at 9:34 AVD 72k1489139 asked Nov 23 '11 at 9:33
C# Mailmessage
may215 4539 add a comment| 3 Answers 3 active oldest votes up vote 1 down vote I am not sure what you are trying to achieve but this will helps you. I assume you're already aware of the DeriveryNotificationOptions property on System.Net.Mail.MailMessage. The only tricky part to using that property is that its enum type represents a bitfield, so you should set it to the sum of the options you want to apply. For example, if you want delivery notification on delay, failure, or success, you should set the property to DeliveryNotificationOptions.Delay + DeliveryNotificationOptions.OnFailure + DeliveryNotificationOptions.OnSuccess Or this is one method to capture the failure report or any error when the mail has not been sent (failure report) // Change your Try-Catch to call the new method named 'CheckExceptionAndResend' // Error handling for sending message try { smtpClient.Send(message); // Exception contains information on each failed receipient } catch (System.Net.Mail.SmtpFailedRecipientsException recExc) { // Call method that will analyze exception and attempt to re-send the email CheckExceptionAndResend(recExc, smtpClient, message); } catch (System.Net.Mail.SmtpException smtpExc) { // Log error to event log using StatusCode information in // smtpExc.StatusCode MsgBox((smtpExc.StatusCode.ToString + " ==>Procedure SmtpException")); } catch (Exception Exc) { // Log error to event log using StatusCode information in // smtpExc.StatusCode MsgBox((E
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine failure sending mail. at system.net.mail.smtpclient.send(mailmessage message) Microsoft Student Partners ISV Startups TechRewards Events Community Magazine failure sending mail c# Forums Blogs Channel 9 Documentation APIs and reference Dev centers Samples Retired content We’re
Smtpclient Sendasync
sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. SmtpClient Class SmtpClient Methods Send Method Send http://stackoverflow.com/questions/8239881/get-sent-mail-error Method Send Method (MailMessage) Send Method (MailMessage) Send Method (MailMessage) Send Method (MailMessage) Send Method (String, String, String, String) TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation is archived and is not https://msdn.microsoft.com/en-us/library/swas0fwc(v=vs.110).aspx being maintained. SmtpClient.Send Method (MailMessage) .NET Framework (current version) Other Versions Visual Studio 2010 .NET Framework 4 Visual Studio 2008 .NET Framework 3.5 .NET Framework 3.0 .NET Framework 2.0 Sends the specified message to an SMTP server for delivery.Namespace: System.Net.MailAssembly: System (in System.dll)Syntax C#C++F#VB Copy public void Send( MailMessage message ) Parametersmessage Type: System.Net.Mail.MailMessageA MailMessage that contains the message to send.Exceptions Exception Condition ArgumentNullExceptionmessage is null.InvalidOperationExceptionThis SmtpClient has a SendAsync call in progress.-or- MailMessage.From is null.-or- There are no recipients specified in MailMessage.To, MailMessage.CC, and MailMessage.Bcc properties.-or- DeliveryMethod property is set to Network and Host is null.-or-DeliveryMethod property is set to Network and Host is equal to the empty string ("").-or- DeliveryMethod property is set to Network and Port is zero, a negative number, or greater than 65,535.ObjectDisposedExceptionThis object has been disposed.SmtpExceptionThe connection
ASP.NET Community Standup Forums Help Home/ASP.NET Forums/General ASP.NET/Getting Started/asp.net email error handling asp.net email error handling [Answered]RSS 3 replies Last post Feb 17, 2009 12:17 https://forums.asp.net/t/1385307.aspx?asp+net+email+error+handling AM by mudassarkhan ‹ Previous Thread|Next Thread › Print Share Twitter Facebook http://snahta.blogspot.com/2009/06/sending-email-with-details-exception.html Email Shortcuts Active Threads Unanswered Threads Unresolved Threads Support Options Advanced Search Reply Dman100 Member 39 Points 434 Posts asp.net email error handling Feb 16, 2009 12:22 AM|Dman100|LINK I have a two part question. I am trying to learn how to handle errors when sending email using failure sending asp.net. I've created a simple web form for testing different errors that can occur when sending an email. I am testing this by sending thru my ISP from my localhost. My first question is how do I write the errors to the event log? Second, what is the best way to throw errors for testing? I tried using Throw(), but failure sending mail that does not seem to work. As an example, I want to test how the exception would be handled when a recipients emailbox was unavailable due to an incorrect email address or say the emailbox was busy due to maintanence or some other type of problem. How would you use throw to test that type of scenario? Thanks for any help. I tried the following: protected void btnSend_Click(object sender, EventArgs e) { SendMail(); } private void SendMail() { MailMessage message = new MailMessage(); message.From = new MailAddress(txtFrom.Text.Trim()); message.To.Add(txtTo.Text.Trim()); message.Subject = txtSubject.Text.Trim(); message.Body = txtBody.Text.Trim(); SmtpClient smtpClient = new SmtpClient(); try { if (txtTo.Text == "test@test.com") throw new SmtpFailedRecipientsException("Mailbox Unavailable"); //smtpClient.Send(message); } catch (SmtpFailedRecipientsException recExc) { for (int recipient = 0; recipient < recExc.InnerExceptions.Length - 1; recipient++) { SmtpStatusCode statusCode; statusCode = recExc.InnerExceptions[recipient].StatusCode; if ((statusCode == SmtpStatusCode.MailboxBusy) || (statusCode == SmtpStatusCode.MailboxUnavailable)) { Thread.Sleep(5000); //smtpClient.Send(message); } else { Response.Write(recExc.InnerExcepti
web.config files for sharepoint based web applications. SharePoint Test Data ToolThis utility is great for generating some test data for sharepoint testing purpose.This tool support seeding the lists SPCore 2010This project is a utility project and will help Developers and Administrators to code faster some of the most common tasks in sharepoint 2010. About Me Speaking Projects Learn Tools Questions SharePoint 2010 Friday, June 19, 2009 Sending email with details exception handling Scenario:Sending email is one of the most common requirement and it usually works great in DEV environment because Mail Server is usually not locked down. But you never know the rules set up in Production.Solution:Robust Error handling is the answer to most production issues.Here's a modified version of the robust email solution in ASP.netCode:private void SendMail(string from, string to , string subject, string body) { //Create message object and populate w/ data from form System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); message.From = new System.Net.Mail.MailAddress(from); message.To.Add(to); message.Subject = subject; message.Body = body; //Setup SmtpClient to send email. Uses web.config settings. System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient(); //Error handling for sending message try { smtpClient.Send(message); } catch (System.Net.Mail.SmtpFailedRecipientsException recExc) { for (int recipient = 0; recipient < recExc.InnerExceptions.Length - 1; recipient++) { System.Net.Mail.SmtpStatusCode statusCode; //Each InnerException is an System.Net.Mail.SmtpFailed RecipientException statusCode = recExc.InnerExceptions[recipient].StatusCode; //Log error to event log. } } //General SMTP execptions catch (System.Net.Mail.SmtpException smtpExc) { //Log error to event log using StatusCode information in //smtpExc.StatusCode } catch (Exception ex) { //Log error to event log. } }Article: SmtpFailedRecipientsException , SmtpException Follow me on Twitter Posted by Sandeep Nahta at @9:06 PM Permanent Link Tags: Code 0 comments: Post a Comment Newer Post Older Post Home Subscribe to: Post Comments (Atom) Archive Archive Feb 2015 (1) May 2014 (1) May 2013 (1) Mar 2013 (1) Feb 2013 (2) Jan 2013 (3) Dec 2012 (1) Sep 2012 (3) Aug 2012 (3) Jul 2012 (1) Jun 2012 (1) Apr 2012 (2) Mar 2012 (1) Feb 2012 (2) Jan 2