How To Know If Email Failed To Reach Its Receivers
Jan 24, 2010
I am sending email using the following utility class, if receiver foo@[URL] is not exist or the email never reach him for one reason or another, I want my application to be notified. It works only when the smtp client failed to connect to the smtp server, I got an exception in this case, otherwise, the only way to know if email fail to reach the client is by checking client account.
public static class EmailUtil
{
/// <summary>
/// Fires exception if string is null or empty
/// </summary>
/// <param name="param">param value</param>
/// <param name="paramName">is the parameter name to be shown in the exception message</param>
private static void CheckStringParam(string parameter, string paramName)
{
if (String.IsNullOrEmpty(parameter))
{
throw new ArgumentException(String.Format("{0} can't be null or empty", paramName));
}
}
public static void SendEmail(EmailArgument emailArg)
{
CheckStringParam(emailArg.FromEmail, "emailArg.FromEmail");
CheckStringParam(emailArg.Subject, "emailArg.Subject");
CheckStringParam(emailArg.Body, "emailArg.Body");
string body = emailArg.Body;
MailMessage mailMsg = new MailMessage();
mailMsg.From = new MailAddress(emailArg.FromEmail);
foreach(string recipient in emailArg.ToEmails)
{
if (String.IsNullOrEmpty(recipient))
{
throw new ArgumentException("One of the values in the emailArg.ToEmails array is null or empty");
}
mailMsg.To.Add(new MailAddress(recipient));
}
mailMsg.IsBodyHtml = emailArg.IsHtml;
if (emailArg.PutHtmlTags)
{
body = String.Format("{0}" + body + "{1}", "<HTML><Body>", "</Body></HTML>");
}
mailMsg.Body = body;
mailMsg.BodyEncoding = emailArg.BodyEncoding;
// Get client info from the config file , it is tested with Web.config, need to be tested with App.config
SMTPConfiguration smtpConfig = (SMTPConfiguration)System.Configuration.ConfigurationManager.GetSection("SMTPConfigurationGroup/SMTPServer");
SmtpClient client = new SmtpClient(smtpConfig.Host, smtpConfig.Port);
client.EnableSsl = smtpConfig.EnableSSL;
client.Credentials = new System.Net.NetworkCredential(smtpConfig.Username, smtpConfig.Password);
// The notifications of failure are sent only to the client email.
// Exceptions are not guranteed to fire if the Receiver is invalid; for example gmail smtp server will fire exception only when receiver@gmail.com is not there.
// Exceptions will be fired if the server itself timeout or does not responding (due to connection or port problem, extra).
mailMsg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
client.Send(mailMsg);
}
}
i am trying to send a email with the info supplied from my form. i have got the code from a book im going through ( asp.net 3.5 in c# and vb ). First here is the code behind from the submit button:
Protected Sub btn_submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim fileName As String = Server.MapPath("~/App_Data/ContactForm.txt") Dim mailBody As String = System.IO.File.ReadAllText(fileName) mailBody = mailBody.Replace("##Name##", tb_firstName.Text) mailBody = mailBody.Replace("##Surname##", tb_surname.Text) mailBody = mailBody.Replace("##eMail##", tb_eMail.Text) mailBody = mailBody.Replace("##Subject##", tb_subject.Text) mailBody = mailBody.Replace("##Description##", tb_description.Text) Dim myMessage As MailMessage = New MailMessage() myMessage.Subject = "##Subject##" myMessage.Body = mailBody myMessage.From = New MailAddress("jay@jwwebdesign.net", "##Name##") myMessage.To.Add(New MailAddress("jay@jwwebdesign.net", "Me")) Dim mySmtpClient As SmtpClient = New SmtpClient() mySmtpClient.Send(myMessage) End Sub
smtp exeption was unhandled by user code Transaction failed. The server response was: m1pismtp01-001.prod.mesa1.secureserver.net and it highlights this code:.........
I'm connecting sucessfully to a WebService but when I try to connect from an "Intranet" to the external WebService i don't have enought rights to reach the external server. Is there any thing that i can do programatically in order to skip these rights?
How to raise combobox_SelectedIndexChanged(object sender, EventArgs e) programmatically? Lets say i have method called ClearFields(). I want to call the event before i hit the end of Clearfields() method.
OK, apparently related questions dont seem to address this directly. An exception reaches Elmah, maybe a repository cant reach a database, but then neither can Elmah reach that database. Even if they target different servers, maybe its a network problem.
Is there a way to configure fallback logs for Elmah for cases like this, e.g. a text file, message queue, email, sms, etc? If so, where do I start looking to do this, excpt for now the Elmah source code.
I am using an instance of DirectoryInfo to browse and retrive the files and some file attributes on a physical directory. This is displayed in a html table. But if you have for example text files (.txt) or word dokuments (.docx) How can I display the correct icon that is associated with the file in my html table? And further on how can I reach the user who modified the file the last time? Where is that info saved?
Is the DirectoryInfo the object I should use for this purpose? or are there other objects or functions that I should looking at?
If I have 2 or 3 different domain names which all point to my same application; is there a way that I can differentiate which of the domain name was used to reach my application? for example if I have both [URL] and [URL] that both reach the same application and I would like to be able to tell which one of those 2 is being used, in code behind?
I've been struggling for some time now with an MVC routing issue, but I have finally reached a point where the basic routing is correct; that is, the application is invoking the correct action method and .aspx page, but the action method fails because no parameters are passed to it.
Before I show detailed screenshots of the problem, I had better provide some background. This is a bibliographic application which, among other things, analyzes text abstracts to identify unique words and the number of occurrences for each word in each document. This data will eventually be inserted into a SQL Server database, but for the time being I only want to do the calculation and display the results, on a document-by-document basis, in an .ASPX view set up for the purpose. The data structure of the application is as follows:
Collections -this is a set of fifty or so CollectionDetails items.CollectionDetails represent individual documents, in this case books in an academic library. Attributes of the CollectionDetail record are those typical of a library book--author, call number, title, year, and so on. The title and subject catalog headings are combined to form a quasi-abstract, which becomes the basis of the text analysis. In a few cases, I added additional text from Google Books or Amazon synopses and reviews.
MasterStopList contains common words such as pronouns and prepositions that we want to exclude from consideration.
i have a Databound Accordionmenu with hyperlinks in its content template. What i wanna do is adding `onMouseOver` animation to these hyperlinks. Normally i would do somthing like :
[Code]....
where the playanim javascript function triggers the animation for the hyperlink. But the thing is, Hyperlinks in the content template are not visible in code, they simply dont exist. when i write the code, it says there is no item called hyperlink1, it doesn`t show up in the intellisense menu either. Is it possible to add an animation inside an Accordionmenu, if yes how can i reach the TargetControls inside the ContentTemplate to trigger the animation.
I am facing problem with webpartzone web parts. Web PartZone LayoutOrientation is set to Horizontal.
It's not getting horizonatlly repeating when it's reach browser end i mean at 100%!!
Or anything anyone can help to do best for web parts postioning ,in my case i have 8 textboxes and i want it to horizontally repeat but it's only in the one row.
I am runnign the SQL 2005 with Membership structure and two web-applications on the same server box. Each web application uses its own Application Name in aspnet_Applications table. There are two application names. The users from web-app1 could not login to web-app2. Each web-apps uses different Application Pool. Each providers section of Membersip use correct applicationName from aspnet_Applications. The first application is working correct.
The problem is that sometimes the users could not login to web-application 2 during day. I get error Event code: 4006 Event message: Membership credential verification failed. The users start to login again after I Recycle - Stop - Start Application Pool of this web application.
Using Role based (Active directory groups) authorization, I am able to control the access to various web pages. If an unauthorized user reaches a web page, a small popup comes up (as shown in the attached bit map) asking for credentials. If the user clicks on "Cancel" button on the popup, it shows "Access denied" error.
Instead of showing the standard "Access denied" error, I want to redirect to another .aspx page with a more meaningful message.
is my session related tag in web.config file but most of the time if i idle 20 minutes then its automatically timedout and went to my login page, is there any solution ?
I am trying to add Failed Request Tracing to my IIS 7/ASP.NET server.
First, I create failed request tracing for "all content, error codes 400-999" because want to save all errors.
Then, I try to create a trace for "all content, time: 5 seconds" because I want to trace all "long" requests. However, IIS 7 gives me an error: "A failed request trace for this content already exists".How can I add this second trace for all content that takes > 5 seconds?
I need to create a form that would work like this Choose Provider :( user would select gmail, yahoo, hotmail, ext) Enter Name: ( user enters there name) Message : ( user enters message) and then the "submit"button.